How to use synchronized() {} as the basis for a freely (un)lockable mutex, using stackthreads

Sean Kelly sean at f4.ca
Wed Jan 9 10:06:36 PST 2008


downs wrote:
> Disclaimer: My StackThreads are neither particularly fast (130 cycles per context switch), nor particularly stable.
> This is primarily intended as a Proof of Concept, even though I do use it in some of my code. :)
> 
> Have you ever wished D had a Mutex class that could be locked or unlocked at any time?

Tango does :-)

> D's synchronized() {} statement is nice and all, but does have some weaknesses, primarily that it can only be used to
> synchronize some scope - it is not possible to unlock the underlying mutex in the middle of a block.

The Tango mutexes can also be used with the 'synchronized' statement. 
However, I'm not sure I like the idea of being inside a 'synchronized' 
block and having the mutex unlocked.  Why not just break the code into 
two sequential 'synchronized' blocks?


Sean



More information about the Digitalmars-d mailing list