wait/notifyAll like in Java
BLS
Killing_Zoe at web.de
Sat Mar 3 06:24:38 PST 2007
Frank Benoit (keinfarbton) schrieb:
> 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?
Subject: Monitor / *Scope(exit)*
Hi Frank,
at least this makes me think :
http://www.digitalmars.com/d/exception-safe.html
especially :
void abc()
{
Mutex m = new Mutex;
lock(m); // lock the mutex
*scope(exit) unlock(m); // unlock on leaving the scope *
foo(); // do processing
}
and :
http://www.digitalmars.com/d/archives/digitalmars/D/learn/Thread_synchronization_5382.html
Given:
synchronized(obj) { ... }
You can consider the opening brace of the synchronized block to be
equivalent to a mutex lock operation where obj is the mutex being
locked. *Exiting the scope* of a synchronized block by any means
releases the lock.
Hope this is usefull , Bjoern
More information about the Digitalmars-d
mailing list