wait/notifyAll like in Java

Juan Jose Comellas jcomellas at gmail.com
Thu Mar 15 06:21:20 PDT 2007


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. In fact, Frank and I have
already talked about this and we have come up with a JObject prototype that
creates the necessary Condition on demand.

This functionality could easily be added to DMD/Phobos if Walter was willing
to apply the attached patch to DMD's runtime in monitor.c.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: _d_monitorget.patch
Type: text/x-diff
Size: 2012 bytes
Desc: Patch to add the _d_monitorget() function to DMD's monitor.c
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20070315/238e96d4/attachment.patch>


More information about the Digitalmars-d mailing list