[Newbies] Acquiring lock, releasing in callback

Sebastian Nozzi sebnozzi at gmail.com
Fri Nov 2 19:19:53 UTC 2012


Hey, cool, thanks a lot!


El 02/11/2012, a las 19:40, Bert Freudenberg escribió:

> On 2012-11-02, at 19:24, Sebastian Nozzi <sebnozzi at gmail.com> wrote:
> 
>> Is it possible to have one thread wait for 2 other threads to finish? Would it also be solved with Semaphores like this?
>> 
>> s1 := Semaphore forMutualExclusion.
>> s2 := Semaphore forMutualExclusion.
>> [ s1 wait. do stuff .... s1 signal] fork.
>> [ s2 wait. do stuff ..... s2 signal ] fork.
>> 
>> s1 wait. 
>> s2 wait.
>> "Here we are sure the two other processes finished, kind of..."
>> 
>> Or is there a more "friendly" way? :-)
> 
> Looks okay to me. But you could make it a bit simpler:
> 
> s1 := Semaphore new.
> s2 := Semaphore new.
> [ do stuff .... s1 signal] fork.
> [ do stuff ..... s2 signal] fork.
> s1 wait. 
> s2 wait.
> 
> Or even:
> 
> s1 := Semaphore new.
> [ do stuff .... s1 signal] fork.
> [ do stuff ..... s1 signal] fork.
> s1 wait; wait.
> 
> - Bert -


More information about the Beginners mailing list