[squeak-dev] is it okay to signal a Semaphore from multiple
processes?
Chris Muller
asqueaker at gmail.com
Tue May 26 22:53:02 UTC 2015
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?
More information about the Squeak-dev
mailing list
|