Optional monitors suggestion

Yuriy via Digitalmars-d digitalmars-d at puremagic.com
Wed May 14 02:16:20 PDT 2014


On Wednesday, 14 May 2014 at 08:37:41 UTC, bearophile wrote:
> What's the syntax to define a class without its __monitor? Are 
> you using an annotation like @no_monitor?
No syntax for that. The __monitor is not present by default 
anywhere. If you need it, you need to define one.

class A
{

}

class B
{
     void* __monitor;
}

{
     A a = new A(); // sizeof a instance is 8
     B b = new B(); // sizeof b instance is 16
     synchronized(a)
     {
         // Internally allocates a monitor and place it to global 
monitor hash map. On synchronize, search the hash map for already 
created monitors.
     }

     synchronized(b)
     {
         // Internally allocates a monitor, and sets b.__monitor 
to it. Pretty much like it was done before, except that __monitor 
field may now have different offset.
     }
}

So the semantics remains the same, you just may want to define a 
__monitor field if you want better performance.


More information about the Digitalmars-d mailing list