Codemesh Runtime v3 C++ API Reference  3.9.205
Public Member Functions | List of all members
xmog_lock_holder Class Reference

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

#include <xmog_lock_holder.h>

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 );
{
// 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:
xmog_lock_holder
A utility class used for synchronizing access to a Java object.
Definition: xmog_lock_holder.h:48

Copyright (c) 1999-2020 by Codemesh, Inc., ALL RIGHTS RESERVED.