On 10/27/14 9:34 AM, ketmar via Digitalmars-d-learn wrote:
On Mon, 27 Oct 2014 09:24:13 -0400
Steven Schveighoffer via Digitalmars-d-learn
<digitalmars-d-learn@puremagic.com> wrote:

Just as a followup, for some reason Mutex is not callable as a shared
object, so you have to make it __gshared.

This is unfortunate, but it is the only way to do it right now.
Because an actual mutex is thread safe, it is not a problem.
p.s. generally you have to write code that can be used with shared vars
with special accuracy. that's why D made a clear distinction between
shared and thread variables and classes. you must explicitly declare
your intention to use something as shared. generally this increases
code safety and allows to writte better code.

But the result is that you can't use a mutex embedded in a shared object without casting (except for when it's the object's Monitor). Ironically, that's the one place you NEED a mutex. It's not a good situation.

this can be somewhat unusual for those who used to use C/C++ before, as
there is no such "guards" though.

The 'shared' system is really underdesigned in D, and needs complete overhaul. The opposite of it (default unshared) is an extremely useful mechanism.

-Steve

Reply via email to