wait/notifyAll like in Java
BLS
Killing_Zoe at web.de
Thu Mar 1 12:44:42 PST 2007
BLS schrieb:
> 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?
>
>
> Hi Frank,
> probabely this hint is simply shi* but
> I suggest to have a look on Dough Leas concurrent library at :
>
> http://g.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html
>
> The package mainly consists of implementations of a few interfaces:
>
> * Sync -- locks, conditions
> * Channel -- queues, buffers
> * Barrier -- multi-party synchronization
> * SynchronizedVariable -- atomic ints, refs etc
> * Executor -- replacements for direct use of Thread
>
> wait() is AFAIK implemented
> try
> {
> while (true)
> lock.wait();
> }
> catch (InterruptedException e)
> {
> }
>
> HTH and Sorry in case that I miss something. ;-)
> Bjoern
Some additional info from *sync.java*
* Main interface for locks, gates, and conditions.
* Sync objects isolate waiting and notification for particular
* logical states, resource availability, events, and the like that are
* shared across multiple threads. Use of Syncs sometimes
* (but by no means always) adds flexibility and efficiency
* compared to the use of plain java monitor methods
* and locking, and are sometimes (but by no means always)
* simpler to program with.
Regards, Bjoern
More information about the Digitalmars-d
mailing list