wait/notifyAll like in Java

Sean Kelly sean at f4.ca
Thu Mar 1 08:59:56 PST 2007


Juan Jose Comellas wrote:
> To achieve what you mention we need to combine D's Object monitor with a
> condition variable. We can create this in Tango based on the
> tango.util.locks.Condition class, but we'd need access to each Object's
> hidden monitor member variable. There is an Object struct in the
> src/phobos/internal/mars.h file present in DMD's distribution that holds
> the pointer to the monitor (which is implemented as a pthread_mutex_t on
> Linux and a CRITICAL_SECTION on Windows) and the monitor functions are in
> the monitor.c file in the same directory. If we could add a function like
> the following one to this file we'd have all we need:
> 
> void *_d_monitorget(Object *);

I've been thinking about providing hooks for manipulating monitors in 
Tango, though I was thinking more of doing so to allow them to be used 
for process synchronization and the like.  The goal being to allow 
objects to be shared between processes without placing any restrictions 
on how they can be used.  This is more of a long-term project, but I 
brought it up because it may apply here.

> Another possibility would be to add this behavior directly to DMD and have
> it available everywhere. It would mean making each Object that is
> synchronized a little bit more heavyweight. On Linux we would have to add a
> pthread_cond_t to the monitor and on Windows we'd have to emulate the
> condition variable with an extra mutex, semaphore and event.
> 
> Which option seems more attractive to everybody?

I'd like to know this as well.


Sean



More information about the Digitalmars-d mailing list