File tree 2 files changed +36
-10
lines changed
core/src/main/scala/scala/collection/parallel
junit/src/test/scala/scala/collection/parallel
2 files changed +36
-10
lines changed Original file line number Diff line number Diff line change @@ -254,12 +254,10 @@ trait ForkJoinTasks extends Tasks with HavingForkJoinPool {
254
254
def execute [R , Tp ](task : Task [R , Tp ]): () => R = {
255
255
val fjtask = newWrappedTask(task)
256
256
257
- if (Thread .currentThread.isInstanceOf [ForkJoinWorkerThread ]) {
258
- fjtask.fork
259
- } else {
260
- forkJoinPool.execute(fjtask)
257
+ Thread .currentThread match {
258
+ case fjw : ForkJoinWorkerThread if fjw.getPool eq forkJoinPool => fjtask.fork()
259
+ case _ => forkJoinPool.execute(fjtask)
261
260
}
262
-
263
261
() => {
264
262
fjtask.sync()
265
263
fjtask.body.forwardThrowable()
@@ -277,12 +275,10 @@ trait ForkJoinTasks extends Tasks with HavingForkJoinPool {
277
275
def executeAndWaitResult [R , Tp ](task : Task [R , Tp ]): R = {
278
276
val fjtask = newWrappedTask(task)
279
277
280
- if (Thread .currentThread.isInstanceOf [ForkJoinWorkerThread ]) {
281
- fjtask.fork
282
- } else {
283
- forkJoinPool.execute(fjtask)
278
+ Thread .currentThread match {
279
+ case fjw : ForkJoinWorkerThread if fjw.getPool eq forkJoinPool => fjtask.fork()
280
+ case _ => forkJoinPool.execute(fjtask)
284
281
}
285
-
286
282
fjtask.sync()
287
283
// if (fjtask.body.throwable != null) println("throwing: " + fjtask.body.throwable + " at " + fjtask.body)
288
284
fjtask.body.forwardThrowable()
Original file line number Diff line number Diff line change
1
+ package scala .collection .parallel
2
+
3
+ import org .junit .Test
4
+ import org .junit .Assert ._
5
+
6
+ import java .util .concurrent .{ForkJoinPool , ForkJoinWorkerThread }, ForkJoinPool ._
7
+
8
+ import CollectionConverters ._
9
+
10
+ class TaskTest {
11
+ @ Test
12
+ def `t10577 task executes on foreign pool` (): Unit = {
13
+ def mkFactory (name : String ) = new ForkJoinWorkerThreadFactory {
14
+ override def newThread (pool : ForkJoinPool ) = {
15
+ val t = new ForkJoinWorkerThread (pool) {}
16
+ t.setName(name)
17
+ t
18
+ }
19
+ }
20
+ def mkPool (name : String ) = new ForkJoinPool (1 , mkFactory(name), null , false )
21
+
22
+ val one = List (1 ).par
23
+ val two = List (2 ).par
24
+
25
+ one.tasksupport = new ForkJoinTaskSupport (mkPool(" one" ))
26
+ two.tasksupport = new ForkJoinTaskSupport (mkPool(" two" ))
27
+
28
+ for (x <- one ; y <- two) assertEquals(" two" , Thread .currentThread.getName)
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments