A monitor for every object

Robert Jacques sandford at jhu.edu
Mon Feb 7 07:33:29 PST 2011


On Mon, 07 Feb 2011 08:20:20 -0500, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> On Fri, 04 Feb 2011 18:29:08 -0500, Sean Kelly <sean at invisibleduck.org>  
> wrote:
>
>> On Feb 4, 2011, at 3:06 PM, Tomek Sowiński wrote:
>>
>>> Steven Schveighoffer napisał:
>>>
>>>> D also allows you to replace it's monitor with a custom monitor object
>>>> (i.e. core.sync.Mutex) so you can have more control over the mutex,  
>>>> assign
>>>> the same mutex to multiple objects, use conditions, etc.  It's much  
>>>> more
>>>> flexible than Java or C# IMO.
>>>
>>> I didn't know, thx. Where is it documented?
>>
>> Only in the docs for the Mutex ctor here:
>>
>> http://www.digitalmars.com/d/2.0/phobos/core_sync_mutex.html
>>
>> By the way, when using Mutex as an object monitor you currently can't  
>> attach dispose event handlers to the object (ie. via std.signals).   
>> That functionality is only supported by the default monitor.  I've  
>> considered changing this, but doing so imposes some weird requirements  
>> on the creators of an external object monitor, like Mutex.
>
> Sean, I could have sworn that mutex can take over multiple objects'  
> monitors.  This would be highly desirable in a complex structure where  
> members of an object should use the same mutex for synchronized calls.
>
> But looking at the docs once again, it looks like it can only be the  
> monitor for one object (as the target object is accepted only on  
> construction).  Is that a limitation we cannot remove?
>
> -Steve

Steve, you can always assign to an object's monitor variable manually. But  
adding this functionality to Mutex's and Object's API would be appreciated.


More information about the Digitalmars-d mailing list