shared Mutex?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 10 05:06:59 PDT 2016


On 6/9/16 9:19 PM, cy wrote:
> On Thursday, 9 June 2016 at 20:53:38 UTC, tcak wrote:
>
>>         (cast()mx).lock();
>
> I was told casting away shared when there are still references to it is
> a bad idea. Like, the Mutex object might get corrupted if the garbage
> collector tries to move it while another thread is using it.

No, the GC doesn't care about shared in almost all circumstances, and 
certainly will not do anything different based on a cast.

> https://dlang.org/faq.html#casting_from_shared

That is if you are going to keep it unshared. Casting away shared 
temporarily is almost a requirement, as nobody writes shared-aware 
functions for types.

-Steve


More information about the Digitalmars-d-learn mailing list