Subj : Re: Boss Told Me You Can't Use Semaphore, But I Have To Do Something like It! To : comp.programming.threads From : Charles Bryant Date : Tue Jul 19 2005 11:19 pm In article <1121807491.741451.96600@g47g2000cwa.googlegroups.com>, Sean Kelly wrote: >Instead of a 1, why not write the app's PID into this memory segment. >So each app waits for 0, writes its PID, then reads to see if its PID >is set. If so, it continues. Not as nice as a semaphore, ... Not as nice especially because it won't work. Suppose there are two presecces, A and B. They might run as follows: A sees 0 A is suspended B runs B sees 0 B writes B B sees B B assumes it has the lock B is suspended A runs A writes A A sees A A assumes it has the lock Oops! It is extremely difficult to invent correct concurrent algorithms - which is why it's nearly always best to use things like semaphores which have been designed by experts and extensively tested. .