wait/notifyAll like in Java

Graham St Jack grahams at acres.com.au
Thu Mar 15 16:15:20 PDT 2007


Sean Kelly wrote:
> Juan Jose Comellas wrote:
>> Graham St Jack wrote:
>>
>>> Frank Benoit (keinfarbton) wrote:
>>>> While porting java stuff, i come to this:
>>>>
>>>> How can I implement a JObject class as a base of all the ported classes
>>>> to have wait/notify/notifyAll with the behaviour like in Java.
>> [...]
>>> I would prefer to explicitly create condition variables (yes, more than
>>> one allowed) in an object, all tied to the object's monitor. The lack of
>>> multiple conditions per object is an issue in Java because you need
>>> complicated schemes involving child objects whenever you need multiple
>>> conditions.
>>>
>>> Explicit creation of conditions is appropriate because most objects with
>>> a monitor don't need conditions.
>>>
>>> This subject has been coming up on and off for years - can we please get
>>> something added to the runtime (if necessary) and to phobos and tango to
>>> implement conditions in a standard way? The lack of conditions tied to
>>> object monitors is a real pain.
>>
>> This functionality is already present in Tango SVN. I have added a
>> function
>> called _d_monitorget() to Tango's runtime library in
>> lib/compiler/{dmd,gdc}/monitor.c. This function allows access to an
>> Object's monitor. I have also modified the Mutex class in Tango to use
>> its
>> own monitor for locking and I have added a MutexProxy class to allow any
>> object to have a mutex interface. With these modifications and the ones
>> made to the tango.util.locks.Condition module it becomes trivial to have
>> multiple condition variables associated to an Object's monitor and to
>> implement the wanted Java-like functionality.
> 
> For what it's worth, this feature will not be present in the next
> release of Tango so it can be evaluated a bit more carefully.  While I
> like what it does, the way it is implemented would be the first
> requirement of its kind (ie. telling the runtime /how/ something must be
> implemented instead of /what/ must be implemented).  I want to take some
> more time to weigh alternatives before adding this feature to an actual
> release.  The optimal solution may simply be to add wait(), notify(),
> and notifyAll() to Object like in Java.  I haven't had the time to think
> it through yet.
> 
> 
> Sean

This is excellent news!!!! Looking forward to this.

Take your time and get it right - but if you do go for the Java-like
approach, please don't limit it to one condition per monitor.

Keep up the good work.



More information about the Digitalmars-d mailing list