is it okay to signal a Semaphore from multiple processes?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

is it okay to signal a Semaphore from multiple processes?

Chris Muller-3
I want to kick off several HTTP downloads simulatenously.  Only after
ALL are done do I want to continue.  So to test if I could use a
single Semaphore to control this:

| s numberOfDownloads |
numberOfDownloads := 5.
s:=Semaphore new.
1 to: numberOfDownloads do: [ : n |
      [(Delay forMilliseconds: (200 to: 700) atRandom) wait.   "<---
simulates HTTP download"
      s signal ] fork  ].
1 to: numberOfDownloads do: [ : n | s wait ].
"... continue ..."

So I have multiple processes sending #signal to the Semaphore is that
okay?  I didn't experience any problems with the above test even
upping the numberOfDownloads to 500.

If #signal were written as:

   excessSignals := excessSignals + 1

then it might be a problem but its a primitive so it is atomic and
therefore should be fine, right?

Reply | Threaded
Open this post in threaded view
|

Re: is it okay to signal a Semaphore from multiple processes?

Chris Muller-3
Sheesh, sorry, of course it is.  This is the whole purpose of Semaphore..

On Tue, May 26, 2015 at 5:53 PM, Chris Muller <[hidden email]> wrote:

> I want to kick off several HTTP downloads simulatenously.  Only after
> ALL are done do I want to continue.  So to test if I could use a
> single Semaphore to control this:
>
> | s numberOfDownloads |
> numberOfDownloads := 5.
> s:=Semaphore new.
> 1 to: numberOfDownloads do: [ : n |
>       [(Delay forMilliseconds: (200 to: 700) atRandom) wait.   "<---
> simulates HTTP download"
>       s signal ] fork  ].
> 1 to: numberOfDownloads do: [ : n | s wait ].
> "... continue ..."
>
> So I have multiple processes sending #signal to the Semaphore is that
> okay?  I didn't experience any problems with the above test even
> upping the numberOfDownloads to 500.
>
> If #signal were written as:
>
>    excessSignals := excessSignals + 1
>
> then it might be a problem but its a primitive so it is atomic and
> therefore should be fine, right?