[Issue 6380] Proposal to make 'shared' usable

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Oct 20 03:09:52 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=6380

Marco Leise <Marco.Leise at gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Marco.Leise at gmx.de

--- Comment #1 from Marco Leise <Marco.Leise at gmx.de> ---
That only works well when you don't use your own synchronization. Otherwise you
may protect stuff in one shared method with your own mutex, and one some other
method you forgot to mark shared, the object's hidden monitor mutex is used,
allowing for two threads to modify the data in parallel.

Just imagine what would happen in this code:

auto cond = cast(shared) new Condition(new Mutex);
synchronized (cond.mutex)
{
   ...
}

... And you just created a new Mutex to protect the Mutex that protects your
critical section.

--


More information about the Digitalmars-d-bugs mailing list