October 27, 2014
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.
that's due to difference betwen plain type and shared type. `shared(Mutex)` is not the same as simply `Mutex`. to use class as shared var you have to declare it as 'shared class'. or at least declare some of class methods as 'shared'.

but for Mutex it's perfectly ok to use it as '__gshared' object.


October 27, 2014
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.

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


October 27, 2014
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
October 27, 2014
On Monday, October 27, 2014 09:24:13 Steven Schveighoffer via Digitalmars-d- learn 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.

The reason that it's not shared is because Sean Kelly didn't want to make much of anything in druntime shared until shared was better ironed out, which keeps getting talked about but never done.

- Jonathan M Davis

October 28, 2014
On Monday, 27 October 2014 at 19:13:13 UTC, Jonathan M Davis via Digitalmars-d-learn wrote:
>
> The reason that it's not shared is because Sean Kelly didn't want to make
> much of anything in druntime shared until shared was better ironed out, which
> keeps getting talked about but never done.

Yep.  There was a fairly productive (brief) discussion on shared in digitalmars.D recently, but no one who can really make such decisions weighed in.  I honestly don't know when shared will get a serious look, despite it being probably the most significant unfinished language feature in D 2.0.
1 2
Next ›   Last »