Optional monitors suggestion

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 16 21:03:11 PDT 2014


On Tuesday, 13 May 2014 at 15:46:51 UTC, Yuriy wrote:
> Hello, I've played a bit with monitors, trying to make them 
> optional, and here's what i've come up with:
> https://github.com/yglukhov/dmd/tree/optional_monitor
> https://github.com/yglukhov/druntime/tree/optional_monitors
>
> The whole idea is that Object doesn't contain __monitor field 
> anymore.
> TypeInfo_Class will hold a monitor offset, if a class defines 
> one (like void* __monitor), or -1.
> Monitor lookup is done with a hash map, if monitorOffset is -1.
> The hash map is protected by a primitive RW spin lock.
> The only downside i see here is that finalization of every 
> object will now lookup for a corresponding monitor, if it's 
> class doesn't define embedded one.
> Tested on Mac, but i think it should work anywhere.
>
> Your feedback is very appreciated. Thanx.

Why not delete it altogether and define a Locakable constraint 
for thing that are Locakable. Only these can be used in 
synchronize.

This will cause to go through 2 indirections for something that 
won't be used on most objects as they are not shared anyway.


More information about the Digitalmars-d mailing list