wait/notifyAll like in Java
kris
foo at bar.com
Thu Mar 1 10:26:19 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 *);
>
> 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?
>
>
> 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.
>>
>>http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html
>>
>>The "synchronized" of D objects, already uses some monitor.
>>Is it possible to access and use it for such an implementation?
>
>
My concern would be twofold:
1) As I understand it, D adds monitors only where it is required --
those scenarios where a synch is applied? If it were to create a monitor
for each and every object created, I think there would be a notable
resource issue :)
2) There some concern over the sharing of such instances. What does it
mean to synchronize on a D monitor, whilst it is also being used for the
above purposes (as a condition, for example) ?
More information about the Digitalmars-d
mailing list