Thread question

I want to parallelize a block of code, say that contains three statements: Statement 1, Statement 2, and Statement 3.

I have created two threads but only one of them should execute statement 2. I mean Thread 1 should execute Statement 1 and Statement 3 while thread 2 should execute Statement 1, Statement 2, and Statement 3.

Is there any way to make Thread 1 skip statement 2.

I don't want to create two parallel regions where one will contain Statement 1 and Statement 3 while the other contains Statement 1, Statement 2, and Statement 3 and let Thread 1 execute region1 and Thread2->Region 2.

[626 byte] By [jlrockya] at [2007-11-27 7:55:40]
# 1
You have two separate tasks, so you should have two separate methods.Alternatively, you could give your Runnable a member variable that you pass to the constructor that indicates whether S2 is to be executed.You really should just have two different methods though.
jverda at 2007-7-12 19:37:05 > top of Java-index,Core,Core APIs...
# 2

As jverd said, it seems like you have 2 very different kinds of Tasks if you want them to be executed by specific Threads. And if you want them executed by specific Threads, then they aren't performing the same work at all. Then why not use different queues to queue up all the tasks of different types?

Dalzhima at 2007-7-12 19:37:05 > top of Java-index,Core,Core APIs...