Something needs to happen with shared, and soon.

deadalnix deadalnix at gmail.com
Mon Nov 12 05:07:46 PST 2012


Le 12/11/2012 13:25, Regan Heath a écrit :
> First off, IIRC object contains a mutex/monitor/critical section, which
> means all objects contain one. The last discussion saw many people
> wanting this removed for efficiency. I propose we do this. Then, if a
> class or struct is declared as "shared" or a "shared" instance of a
> class or struct is constructed we magically include one (compiler magic
> which I hope is possible).
>

As already explain in the thread you mention, it is not gonna work. The 
conclusion of the thread is that only synchronized classes should have 
one mutex field.

> Secondly I say we make "shared" illegal on basic types. This is a
> limitation(*) but I believe in most cases a single int is unlikely to be
> shared without an accompanying group of other variables, and usually an
> algorithm operating on those variables. These variables and the
> algorithm should be encapsulated in a class or struct - which can in
> turn be shared.
>

Shared reference counting ? Disruptor ?

> Now.. the synchronized() {} statement can do the magic described above
> (as ScopedLock) for us. It would be illegal to call it on a non "shared"
> instance. It would acquire the mutex and cast away "shared" inside the
> block/scope, at the end of the scope it would cast shared back and
> release the mutex.
>
> (*) for those rare cases where a single int or other basic type is all
> that is shared we can provide a wrapper struct which is declared as
> "shared".
>


More information about the Digitalmars-d mailing list