semaphores do not access like volatile

Bob Arning arning at charm.net
Mon Feb 10 12:54:10 UTC 2003


On Mon, 10 Feb 2003 13:02:55 +0100 Niko Schwarz <niko.schwarz at gmx.net> wrote:
>Am Montag, 10. Februar 2003 13:23 schrieb diegogomezdeck at consultar.com:
>> How are you creating the Semaphore? with #forMutualExclusion message?
>
>with new. tbh i never understood the difference. 

The difference is that #forMutualExclusion signals the newly-created Semaphore so that the first #wait will proceed straight through, although you could easily use #new and then #signal yourself. The essential question is "Does this new Semaphore represent a resource that is available or unavailable at the time of creation?"

If you are using the Semaphore to (e.g.) guard a section of code against multiple concurrent executions, then the code is presumably available when you create the Semaphore.

If you are using the Semaphore to (e.g.) signal data available from some source, then it is likely that the data will not be available when you create the Semaphore.

Cheers,
Bob



More information about the Squeak-dev mailing list