Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

xmog_lock_holder Class Reference
[Concurrency]

A utility class used for synchronizing access to a Java object. More...

#include <xmog_lock_holder.h>

Collaboration diagram for xmog_lock_holder:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 xmog_lock_holder (xmog_java_ref &_toLock)
 Attempts to lock the given proxy object on the Java side.
 ~xmog_lock_holder ()
 Unlocks the proxy object on the Java side.

Detailed Description

A utility class used for synchronizing access to a Java object.

In Java, you can write thread-safe code by protecting access to code blocks with the synchronized keyword, for example:

       Object      lock;
   
       synchronized( lock )
       {
           // do something that must only be accessible to one thread at a time
       }

In C++, you could directly use the xmog_java_ref.xmog_monitor_enter or xmog_java_ref.xmog_monitor_exit methods, but the xmog_lock_holder utility class is much more convenient.

The above code translates into C++ as follows:

       Object      lock( _use_java_ctor );
   
       {
           xmog_lock_holder( lock );
   
           // do something that must only be accessible to one thread at a time
       }

The scope defined by the parentheses defines the lifetime of the xmog_lock_holder instance. The constructor invokes the xmog_monitor_enter() method and the destructor invokes the xmog_monitor_exit() method.


The documentation for this class was generated from the following file:
Generated on Wed May 31 14:01:33 2006 for Shared Codemesh Runtime Library API Reference by  doxygen 1.4.1