synchronized (this[.classinfo]) in druntime and phobos

Dmitry Olshansky dmitry.olsh at gmail.com
Tue May 29 05:19:35 PDT 2012


On 29.05.2012 16:07, Regan Heath wrote:
>
> According to the docs here:
> http://dlang.org/class.html#synchronized-functions
>
> A synchronized function locks "this" and as "this" is exposed
> publicly... In the following code the "lock" statement and "synchronized
> void bar" lock the same mutex.
>
> class Foo {
> synchronized void bar() { ...statements... }
> }
>
> void main()
> {
> Foo foo = new Foo();
> lock(foo)
> {
> ...statements...
> }
> }
>
>> But locking on another class rather than something specifically
>> intended as a mutex does seem to me like it's asking for trouble.

I'd be darned but every Object in D has monitor fields. If I'm not 
mistaken it's the mutex you are looking for ;)


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list