Use 2 semaphores.
pseudo code

sem_1(1);
sem_2(0);

THREAD A;                                                THREAD B
sem_1_wait();                                             sem_2_wait();
 ...                                                                ....
sem_2_signal();                                          sem_1_signal();

This makes sure that the threads interleave in an appropriate manner.


On Thu, Sep 29, 2011 at 3:09 AM, htross <htb...@gmail.com> wrote:

> There are two threads, one produces even number and other produces
> odd
> number, how will you print the consecutive numbers.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to