Question

Each Java object (and its class) has an associated monitor. In pthread terms a Java monitor is equivalent to the combination of a reentrant mutex and a condition variable.

For locking, the Win32 API provides Mutex objects (which are reentrant but heavyweight) and Critical Sections (which are non-reentrant but lightweight). It also provides other synchronization constructs such as Semaphores and Events but has no explicit concept of a condition variable.

If I were writing a JVM, how could I use these Win32 concepts to implement Java monitors?

Was it helpful?

OTHER TIPS

Windows has SignalObjectAndWait() which can be used very much like a wait on a condition variable in a monitor. You can use an Event (that is Reset) and a Mutex and then use PulseEvent() to do the equivalent of signalling the condition variable.

I suggest you take a look at the OpenJDK source to see how the class ReentrantLock was implemented.

(I haven't checked it myself so i'm not sure of the answer).

the util.concurrent locks are implemented using native API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top