I am trying to write a program that utilizes 3 threads and prints 0,1,2,3,4,5,…. and so on.
Thread 1 – prints 0,3,6,9 and so on
Thread 2 – prints 1,4,7,10 and so on
Thread 3 – prints 2,5,8,11 and so on
Can anyone please help me in writing the code for this?
One possible solution involves messages queues. Each thread has a message queue.
0, then sends0to message queue 2.Thread 3 reads value from message queue 3, increments it and then sends new value to message queue 1
From here, you should infer what thread 1 shall do next.