0

I have four threads t1,t2,t3,t4 acting on same object of the class.I have some restriction,t2 should execute only after t1 has executed and t3 should execute only after t2 has executed,and same is the case with t4.I mean sequence should compulsarily be t1 then t2 then t3 then t4.How can we make sure that these four threads will execute in sequence only.

1
  • Don't confuse "thread" with "task". T1, T2, T3, and T4 don't sound like threads, they sound like tasks. (see Kayaman's answer) Commented Apr 13, 2014 at 20:07

2 Answers 2

6

If you need to control the sequence like that, you don't have parallelism, and multithreading is useless. You seem to need only a single thread that will perform those operations sequentially.

Sign up to request clarification or add additional context in comments.

Comments

0

trying using something known as a 'semaphore' .its basically a lock and key mechanism which will allow a single thread to run at a time provided they acquire a lock and release it when they are done.

example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.