summaryrefslogtreecommitdiff
path: root/src/library/scala/concurrent/impl
Commit message (Collapse)AuthorAgeFilesLines
* Fix some typos in `spec` documents and comments.Dongjoon Hyun2016-03-151-1/+1
|
* Remove unused imports and other minor cleanupsSimon Ochsenreither2015-12-182-6/+6
| | | | | | | | | | - Language imports are preceding other imports - Deleted empty file: InlineErasure - Removed some unused private[parallel] methods in scala/collection/parallel/package.scala This removes hundreds of warnings when compiling with "-Xlint -Ywarn-dead-code -Ywarn-unused -Ywarn-unused-import".
* Remove ThreadPoolExecutor fallback in ExecutionContextImplSimon Ochsenreither2015-10-281-31/+12
| | | | | | | | | | | The method createDefaultExecutorService had a fallback if the creation of a ForkJoinPool didn't succeed. This was necessary, because Scala shipped its own version of FJP, and the dependency on sun.misc.Unsafe (which is not an "offical" official API) made portability slightly questionable. Now that we can assume that FJP is supplied by the JDK, this concern goes away.
* Unfinalize the class DefaultPromiseJason Zaugg2015-08-131-6/+8
| | | | | | | | | | | | | | | | | It was non-final in Scala 2.11.x, and made final as part of fa0743c32. Removing the final modifier seems like the cleanest way to enable conversions like `javaFuture.toScala.toJava` to return the original `javaFuture` in scala-java8-compat. I have made the methods defined in this class final as an alternative lockdown. Discussion, Motivation: https://github.com/scala/scala-java8-compat/pull/46 https://github.com/scala/scala-java8-compat/pull/50
* Remove our fork of forkjoin. Java 8 bundles it.Adriaan Moors2015-07-151-2/+1
| | | | | | | | | | | | | | | | | | | | | Provide deprecated compatibility stubs for the types and static members, which forward as follows: ``` scala.concurrent.forkjoin.ForkJoinPool => java.util.concurrent.ForkJoinPool scala.concurrent.forkjoin.ForkJoinTask => java.util.concurrent.ForkJoinTask scala.concurrent.forkjoin.ForkJoinWorkerThread => java.util.concurrent.ForkJoinWorkerThread scala.concurrent.forkjoin.LinkedTransferQueue => java.util.concurrent.LinkedTransferQueue scala.concurrent.forkjoin.RecursiveAction => java.util.concurrent.RecursiveAction scala.concurrent.forkjoin.RecursiveTask => java.util.concurrent.RecursiveTask scala.concurrent.forkjoin.ThreadLocalRandom => java.util.concurrent.ThreadLocalRandom ``` To prepare for Java 9, the Scala library does not itself use `sun.misc.Unsafe`. However, for now, it provide a convenience accessor for it via `scala.concurrent.util.Unsafe`. This (deprecated) class will be removed as soon as the eco-system drops its use (akka-actor, I'm looking at you).
* SI-8955 Fix hanging fork-join pool via parallel collectionsJason Zaugg2014-11-051-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A recent change [1] to Scala's default fork join thread pool caused intermittent deadlocks. This is only visible in the development series of Scala, 2.12.0-SNAPSHOT. We changed our thread factory to place a hard limit the number of threads created (equal to the desired parallelism.) I have extracted a test case [2] that uses jsr166e directly, rather than using Scala's parallel collections and abstractions on top of FJ. In the comments of the bug, Viktor suggests this was too aggressive and instead we ought to increase the limit to parallelism + 256 (with a system property override.) He explained: > The number 256 is going to be the default for the max threads for > FJP in Java9 (down from 32k) so this change will harmonize the > settings while making it possible to override from the outside. > > The cause of the deadlock is twofold: > > 1) The test uses ExecutionContext.global, which is not designed > for typical ForkJoin workloads since it has async = true > (FIFO instead of LIFO) > 2) And we capped the default max number of threads to be created > when doing managed blocking from 32k to number of cores > (a tad too aggressive it seems) Through testing, I found that for this example I could trigger the hang with: parallelismLevel | maxThreads ----------------------------- 2 | <= 4 4 | <= 9 8 | <= 11 16 | <= 15 I have emailed concurrency-interest [3] to help analyse the problem further, but in the interest of avoiding hangs in the scalacheck/parallel-collections test, I'm implementing Viktor's suggestion in the interim. [1] https://github.com/scala/scala/pull/4042 [2] https://gist.github.com/retronym/2e14cdab6d5612562d95 [3] http://markmail.org/message/czphdyjxpkixeztv
* Add missing canonical combinators:Viktor Klang2014-10-204-206/+235
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - `def transform[S](f: Try[T] => Try[S])(implicit executor: ExecutionContext): Future[S]` - `def transformWith[S](f: Try[T] => Future[S])(implicit executor: ExecutionContext): Future[S]` - `def flatten[S](implicit ev: T <:< Future[S]): Future[S]` - `def zipWith[U, R](that: Future[U])(f: (T, U) => R)(implicit executor: ExecutionContext): Future[R]` Add missing utilities: - `val unit: Future[Unit]` in `object Future` - `object never extends Future[Nothing]` in `object Future` - `def defaultBlockContext: BlockContext` in `object BlockContext` - `def toString: String` on stdlib implementations of `Future` Refactors: - the `scala.concurrent.Future` trait to not explicit create any `Promises`, so that implementations can control implementation type, this is mainly facilitated through adding of the `transform` and `transformWith` methods. - the implementation of `ExecutionContextImpl` has been cleaned up - the `scala.concurrent.impl.DefaultPromise` has been reimplemented to not use `sun.misc.Unsafe` Securing: - Add a self-check in `completeWith` and `tryCompleteWith` to avoid cycles in trait Promise - Capping the maximum number of threads for the global `ExecutionContext` to the max parallelism - Implementing (almost) all `Future` combinators on `transformWith` and `transform` means that `DefaultPromise` linking works on both `(flat)map` and `recover(With)` - Nested `blocking {}` should not spawn extra threads beyond the first. Removes: - the private `internalExecutor` method in favor of an import in trait `Future` - the private `internalExecutor` method in favor of an import in trait `Promise` - the `AtomicReferenceFieldUpdater` in `AbstractPromise` since we're using `Unsafe` - `scala.concurrent.impl.Future` is no longer needed Deprecates: - `Future.onSuccess` - discourage the use of callbacks (and is also redundant considering `foreach` and `onComplete`) - `Future.onFailure` - discourage the use of callbacks (and is also redundant considering `onComplete` and `failed.foreach`) - `ExecutionContext.prepare` - it was ill specced and it is too easy to forget to call it (or even know when to call it or call it more times than needed) - All classes in scala.concurrent.forkjoin. Scala 2.12 will be Java 8+ and as such the jsr166e should be used as included in java.util.concurrent. Reimplements: - `failed` - in terms of `transform` - `map` - in terms of `transform` - `flatMap` - in terms of `transformWith` - `recover` - in terms of `transform` - `recoverWith` - in terms of `transformWith` - `zip` - in terms of `flatMap` + `map` - `fallbackTo` - in terms of `recoverWith` + `recoverWith` - `andThen` - in terms of `transform` Miscellaneous: - Giving the threads of `ExecutionContext.global` sensible names - Optimizes `object Future.successful` and `object Future.failed` are now separate implementations, to optimize for the result, avoiding doing work for the "other branch". - Optimizes `compressedRoot()` by avoiding double-calls to volatile get. Documentation: - Almost all methods on `Future` and `Promise` have been revisited and had their ScalaDoc updated Tests: - Yes
* Revise paragraph (a revised #3164)Paolo G. Giarrusso2013-11-231-3/+3
| | | Revise text further, following suggestions in #3164 and part of the suggestions by @som-snytt. But I've kept "appear", since this paragraph documents the external behavior, not the implementation.
* Cull extraneous whitespace.Paul Phillips2013-09-181-1/+1
| | | | | | | | | | | | | | | | | | | | | One last flurry with the broom before I leave you slobs to code in your own filth. Eliminated all the trailing whitespace I could manage, with special prejudice reserved for the test cases which depended on the preservation of trailing whitespace. Was reminded I cannot figure out how to eliminate the trailing space on the "scala> " prompt in repl transcripts. At least reduced the number of such empty prompts by trimming transcript code on the way in. Routed ConsoleReporter's "printMessage" through a trailing whitespace stripping method which might help futureproof against the future of whitespace diseases. Deleted the up-to-40 lines of trailing whitespace found in various library files. It seems like only yesterday we performed whitespace surgery on the whole repo. Clearly it doesn't stick very well. I suggest it would work better to enforce a few requirements on the way in.
* Merge remote-tracking branch 'scala/2.10.x' into merge-2.10.xGrzegorz Kossakowski2013-07-291-21/+189
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: bincompat-backward.whitelist.conf bincompat-forward.whitelist.conf src/compiler/scala/reflect/reify/phases/Reshape.scala src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala src/compiler/scala/tools/nsc/transform/Mixin.scala src/compiler/scala/tools/nsc/typechecker/RefChecks.scala src/compiler/scala/tools/nsc/typechecker/Typers.scala src/library/scala/concurrent/impl/Promise.scala src/reflect/scala/reflect/internal/StdAttachments.scala test/files/neg/macro-override-macro-overrides-abstract-method-b.check test/files/run/t7569.check
| * SI-7336 - Link flatMapped promises to avoid memory leaksRich Dougherty2013-07-061-22/+190
| |
* | Merge branch 'pr/merge-2.10.2' into masterPaul Phillips2013-06-041-43/+42
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * pr/merge-2.10.2: SI-7375 ClassTag for value class aliases SI-7507 Fix lookup of private[this] member in presence of self type. SI-7532 Fix regression in Java inner classfile reader SI-7517 Fix higher kinded type inference regression SI-7516 Revert "SI-7234 Make named args play nice w. depmet types" A test case for a recent LUB progression. SI-7421 remove unneeded extra-attachement in maven deploy SI-7486 Regressions in implicit search. SI-7509 Avoid crasher as erronous args flow through NamesDefaults SI-6138 Centralize and refine detection of `getClass` calls SI-7497 Fix scala.util.Properties.isMac SI-7473 Bad for expr crashes postfix Increase build.number to 2.10.3 SI-7391 Always use ForkJoin in Scala actors on ... ... Java 6 and above (except when the porperty actors.enableForkJoin says otherwise) Reimplementing much of the DefaultPromise methods Optimizations: 1) Avoiding to call 'synchronized' in tryComplete and in tryAwait 2) Implementing blocking by using an optimized latch so no blocking ops for non-blockers 3) Reducing method size of isCompleted to be cheaper to inline 4) 'result' to use Try.get instead of patmat c.typeCheck(silent = true) now suppresses ambiguous errors Conflicts: bincompat-backward.whitelist.conf bincompat-forward.whitelist.conf src/compiler/scala/reflect/macros/contexts/Typers.scala src/compiler/scala/reflect/reify/package.scala src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala src/compiler/scala/tools/nsc/typechecker/Typers.scala src/compiler/scala/tools/reflect/ToolBoxFactory.scala src/library/scala/concurrent/impl/Promise.scala src/reflect/scala/reflect/internal/Types.scala
| * Reimplementing much of the DefaultPromise methodsViktor Klang2013-05-181-43/+42
| | | | | | | | | | | | | | | | Optimizations: 1) Avoiding to call 'synchronized' in tryComplete and in tryAwait 2) Implementing blocking by using an optimized latch so no blocking ops for non-blockers 3) Reducing method size of isCompleted to be cheaper to inline 4) 'result' to use Try.get instead of patmat
* | SI-7399 : Take scala.concurrent.context.maxThreads into accountRaphael Jolly2013-05-291-11/+11
| | | | | | | | | | This change fixes the bug whereby specifiying maxThread as a property has no effect. A small refactoring is applied in the process.
* | Merge v2.10.1-326-g4f8c306' into merge/v2.10.1-326-g4f8c306-to-masterJason Zaugg2013-05-173-20/+23
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ================================================================ Merge commit 'v2.10.1-326-g4f8c306' into merge/v2.10.1-326-g4f8c306-to-master Conflicts: src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala src/reflect/scala/reflect/runtime/JavaMirrors.scala ================================================================ Merge -s ours 4e64a27 ([nomaster commit range]) ================================================================ Merge commit '0ae7e55' into merge/v2.10.1-326-g4f8c306-to-master Conflicts: src/compiler/scala/tools/nsc/typechecker/Macros.scala
| * Eliminated the accumulated feature warnings.Paul Phillips2013-04-231-5/+5
| | | | | | | | | | | | | | | | | | No, this isn't busywork, how dare you suggest such a thing. I intend my tombstone to say HERE LIES EXTEMPORE, WHO ELIMINATED A LOT OF SIP-18 WARNINGS REST IN PEACE
| * Merge branch 2.10.1 into masterAdriaan Moors2013-02-271-15/+15
| |\ | | | | | | | | | | | | | | | Conflicts: src/compiler/scala/tools/nsc/ast/Trees.scala src/library/scala/concurrent/impl/ExecutionContextImpl.scala
| * | More explicit empty paren lists in method calls.Jason Zaugg2013-02-241-3/+3
| | |
| * | Merge commit '81d8f9d3da' into merge-210Paul Phillips2013-02-092-9/+27
| |\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * excluded from merge: [nomerge] SI-6667 Demote a new ambiguity error to a lint warning. Revert "SI-6422: add missing Fractional and Integral alias in scala package" [backport] SI-6482, lost bounds in extension methods. * commit '81d8f9d3da': (31 commits) reflecting @throws defined in Scala code pullrequest feedback SI-5833 Fixes tail-of-Nil problem in RefinedType#normalizeImpl SI-6017 Scaladoc: Show all letters without dangling links SI-6017 Generate Scaladoc's index links in Scala side SI-5313 Minor code cleanup for store clobbering SI-5313 Test clobbers on the back edge of a loop SI-7033 Be symful when creating factory methods. SI-7022 Additional test case for value class w. bounds SI-7039 unapplySeq result type independent of subpattern count evicts javac-artifacts.jar SI-7008 @throws annotations are now populated in reflect Fix SI-6578. Deprecated `askType` because of possible race conditions in type checker. SI-7029 - Make test more robust SI-7029 - Makes sure that uncaught exceptions are propagated to the UEH for the global ExecutionContext SI-6941 tests SI-6686 drop valdef unused in flatMapCond's block ... Conflicts: src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala src/reflect/scala/reflect/internal/Definitions.scala
| * | | Remove unused imports in library.Paul Phillips2012-11-191-1/+1
| | | |
* | | | SI-7383 - Call ExecutionContext.prepare in Future.apply to allow for ↵Viktor Klang2013-05-101-1/+1
| |_|/ |/| | | | | | | | capturing local context like ThreadLocals and then re-establishing them prior to execution, as per intention of EC.prepare
* | | SI-7146 - Fixing checkinit bug in ExecutionContextImpl and adding testViktor Klang2013-02-191-4/+4
| | |
* | | [nomaster] refactor AdaptedForkJoinTask, uncaughtExceptionHandlerAdriaan Moors2013-02-091-18/+15
| |/ |/| | | | | | | | | Inlined AdaptedForkJoinTask, made uncaughtExceptionHandler private[this]. This is necessary to maintain binary compatibility with 2.10.0.
* | SI-7029 - Makes sure that uncaught exceptions are propagated to the UEH for ↵Viktor Klang2013-01-312-9/+27
|/ | | | the global ExecutionContext
* Brings all copyrights (in comments) up-to-date, from 2011/12 to 2013Heather Miller2012-11-024-9/+9
|
* Don't write side-effecting nullary methods.Paul Phillips2012-09-261-2/+2
| | | | | | | | | | | | Style says never write methods like this: def foo: Unit If it is Unit, then it is side-effecting, and should be def foo(): Unit Since -Xlint warns about this, we must adhere to its dictate.
* Adjustments to scala.concurrent.duration.Paul Phillips2012-09-191-8/+4
| | | | | | | | More use of implicit classes and value classes; aliased units to make importing TimeUnit and TimeUnit._ unnecessary; placed some classes in their own files because "the unit of compilation is the file" and we shouldn't bundle more than necessary; fixed some examples.
* move Duration (incl. DSL) into scala.concurrent.duration packageRoland2012-09-191-1/+1
| | | | | | | | | so that the full package can be imported naturally: import scala.concurrent.duration._ will give you all the types (Duration, FiniteDuration, Deadline) and the DSL for constructing these.
* improve Promise.tryAwait by converting to match statementRoland2012-09-121-10/+9
| | | | | - also use type FiniteDuration due to a previous change to Deadline’s type signature
* improve docs and Promise implRoland2012-09-111-17/+13
| | | | | | | - scaladoc the exceptions thrown by Await.* and Awaitable.* - move intercept[Exception] into partest’s TestUtil object - improve Promise.tryAwait implementation following Viktor’s comments and make use of Deadline to avoid calling System.nanoTime too often
* fix usage of Duration in Promise implRoland2012-09-102-10/+24
| | | | | | | | | - correctly treat MinusInf and Undefined - don't toMillis in the timeout message (could be MinusInf) - also notice that Inf did not actually wait unbounded - and further notice that tryAwait swallows InterruptedException instead of bailing out early => changed to do so and added throws annotation - also removed some unused imports of Duration
* Added tests, removal of unnecessary methods, fixes prepareHeather Miller2012-08-071-6/+3
|
* SI-6185 - add "prepare" hook to ExecutionContextphaller2012-08-051-3/+9
| | | | | Enables important abstractions to be built on top of futures, such as Twitter's "Local" for handling data local to a callback chain.
* Basing Futures on Try instead of EitherHeather Miller2012-08-042-33/+33
|
* Clean ups in impl.Futurephaller2012-07-192-13/+4
|
* Critical bugfixes/leak fixes/API corrections + ScalaDoc for SIP-14Viktor Klang2012-07-192-14/+5
|
* SI-6095, SI-6098 - clean up public API, add deprecationsphaller2012-07-182-20/+4
| | | | | | | | | | | Remove Scheduler, Cancellable, and Task trait. Hide impl.Promise object. Deprecate managedBlock methods in TaskRunners. Remove duplicate toBoxed method and pointless renaming import. Remove duplicate import of CanBuildFrom and Builder in Future. Organize imports in impl.Promise. Review by @axel22 and @heathermiller
* Changing to scala.concurrent.context. as namespace for the system properties ↵Viktor Klang2012-07-131-6/+5
| | | | for the global execution context
* Fixing oversight in propagating the runnable into the newly created thread.Viktor Klang2012-07-131-1/+1
|
* Squashed critical enhancements to SIP-14: daemonizing global EC, giving EC ↵Viktor Klang2012-07-133-42/+51
| | | | to DelayedLazyVal, removing currentExecutionContext, removing impl.Future.isFutureThrowable, implementing asExecutionContext, giving a decent fallback if ForkJoinPool cannot be created
* Collection of updates to SIP-14 (scala.concurrent)Havoc Pennington2012-07-093-138/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Developed by Viktor Klang and Havoc Pennington - add Promise.isCompleted - add Future.successful and Future.failed - add ExecutionContextExecutor and ExecutionContextExecutorService for Java interop - remove defaultExecutionContext as default parameter value from promise and future - add ExecutionContext.Implicits.global which must be explicitly imported, rather than the previous always-available value for the implicit EC - remove currentExecutionContext, since it could create bugs by being out of sync with the implicit ExecutionContext - remove Future task batching (_taskStack) and Future.releaseStack This optimization should instead be implemented either in a specific thread pool or in a specific ExecutionContext. Some pools or ExecutionContexts may not want or need it. In this patch, the defaultExecutionContext does not keep the batching optimization. Whether it should have it should perhaps be determined through benchmarking. - move internalBlockingCall to BlockContext and remove currentExecutionContext In this patch, BlockContext must be implemented by Thread.currentThread, so the thread pool is the only place you can add custom hooks to be run when blocking. We implement BlockContext for the default ForkJoinWorkerThread in terms of ForkJoinPool.ManagedBlocker. - add public BlockContext.current and BlockContext.withBlockContext These allow an ExecutionContext or other code to override the BlockContext for the current thread. With this API, the BlockContext is customizable without creating a new pool of threads. BlockContext.current is needed to obtain the previous BlockContext before you push, so you can "chain up" to it if desired. BlockContext.withBlockContext is used to override the context for a given piece of code. - move isFutureThrowable into impl.Future - add implicitNotFound to ExecutionContext - remove default global EC from future {} and promise {} - add ExecutionContext.global for explicit use of the global default EC, replaces defaultExecutionContext - add a timeout to scala-concurrent-tck tests that block on SyncVar (so tests time out rather than hang) - insert blocking{} calls into concurrent tck to fix deadlocking - add NonFatal.apply and tests for NonFatal - add OnCompleteRunnable marker trait This would allow an ExecutionContext to distinguish a Runnable originating from Future.onComplete (all callbacks on Future end up going through onComplete). - rename ListenerRunnable to CallbackRunnable and use for KeptPromise too Just adds some clarity and consistency.
* SI-5981, SI-5979, SI-5973 Closed. Maintenance to Try.Heather Miller2012-07-053-37/+2
|
* rework Future.dispatchFuture a bit to fix bugs / optimizeHavoc Pennington2012-06-132-49/+82
| | | | | | | | | | | | | | | | This fixes a bug where _taskStack could batch a task into the wrong executor, as previously commented in the code. It now uses the _taskStack machinery for the Future.apply dispatch in addition to callback dispatch, so we can batch Future(body) as well. Less significantly, it micro-optimizes by combining some different closures and Runnable into a Task object, so there aren't as many objects created when storing and dispatching a callback. So it saves a bit of memory and runtime perhaps.
* Add configuration for ExecutionContextphaller2012-06-051-7/+21
|
* Move implicit ExecutionContext to be determined by lexical scopephaller2012-05-242-10/+13
| | | | | | | | | | | | | | Port of a pull request originally submitted by @havocp. - declare the invariant that all app callbacks have an associated ExecutionContext provided at the place the callback is passed to a method on Future - always run callbacks in their associated EC - since all callbacks have their own EC, Promise does not need one - "internal" callbacks don't need to defer execution either since we know the ultimate app callback will do so, therefore we can use an immediate executor for these
* SIP-14: clean ups and fixesphaller2012-05-173-38/+52
|
* Move resolver and resolveEither to impl.Promisephaller2012-05-103-5/+19
|
* Remove newPromise methodphaller2012-05-031-2/+0
|
* Resolve merge conflictsphaller2012-05-034-64/+31
|\
| * Refactor Unsafe related stuff in scala.concurrent.Aleksandar Prokopec2012-05-013-45/+22
| |