Skip to main content
FRAMES NO FRAMES

Class IloFastMutex

Definition file: ilconcert/ilothread.h
Map of IloFastMutexIloFastMutexIloFastMutex
Synchronization primitives adapted to the needs of Concert Technology.

The class IloFastMutex provides synchronization primitives adapted to the needs of Concert Technology. In particular, an instance of the class IloFastMutex is a nonrecursive mutex that implements mutual exclusion from critical sections of code in multithreaded applications. The purpose of a mutex is to guarantee that concurrent calls to a critical section of code in a multithreaded application are serialized. If a critical section of code is protected by a mutex, then two (or more) threads cannot execute the critical section simultaneously. That is, an instance of this class makes it possible for you to serialize potentially concurrent calls.

Concert Technology implements a mutex by using a single resource that you lock when your application enters the critical section and that you unlock when you leave. Only one thread can own that resource at a given time.

Protection by a Mutex

A critical section of code in a multithreaded application is protected by a mutex when that section of code is encapsulated by a pair of calls to the member functions IloFastMutex::lock and IloFastMutex::unlock.

State of a Mutex

A mutex (an instance of IloFastMutex) has a state; the state may be locked or unlocked. You can inquire about the state of a mutex to determine whether it is locked or unlocked by using the member function IloFastMutex::isLocked. When a thread enters a critical section of code in a multithreaded application and then locks the mutex defining that critical section, we say that the thread owns that lock and that lock belongs to the thread until the thread unlocks the mutex.

Exceptions

The member functions IloFastMutex::lock and IloFastMutex::unlock can throw exceptions. These are the possible exceptions:

System Class: Memory Management

IloFastMutex is a system class.

Most Concert Technology classes are actually handle classes whose instances point to objects of a corresponding implementation class. For example, instances of the Concert Technology class IloNumVar are handles pointing to instances of the implementation class IloNumVarI. Their allocation and de-allocation in internal data structures of Concert Technology are managed by an instance of IloEnv.

However, system classes, such as IloFastMutex, differ from that pattern. IloFastMutex is an ordinary C++ class.

Instances of IloFastMutex are not automatically de-allocated by a call to IloEnv::end.

Furthermore, you should not allocate—neither directly nor indirectly—any instance of IloFastMutex in the Concert Technology environment because the destructor for that instance of IloFastMutex will never be called automatically by IloEnv::end when it cleans up other Concert Technology objects in the Concert Technology environment. In other words, allocation of any instance of IloFastMutex in the Concert Technology environment will produce resource leaks.

For example, it is not a good idea to make an instance of IloFastMutex part of a conventional Concert Technology model allocated in the Concert Technology environment because that instance will not automatically be de-allocated from the Concert Technology environment along with the other Concert Technology objects.

De-allocating Instances of IloFastMutex

Instances of IloFastMutex differ from the usual Concert Technology objects because they are not allocated in the Concert Technology environment, and their de-allocation is not managed automatically for you by IloEnv::end.

Method Summary
public IloFastMutex()
public intisLocked()
public voidunlock()
public ~IloFastMutex()
Method Detail

IloFastMutex

public IloFastMutex()

This constructor creates an instance of IloFastMutex. Note that instances of this class are not allocated in a Concert Technology environment and corresponding resources are thus not automatically released when calling IloEnv::end(). This mutex contains operating system-specific resources to represent a lock. You may use this mutex for purposes that are private to a process. Its behavior is undefined for inter-process locking.


~IloFastMutex

public ~IloFastMutex()

The delete operator calls this destructor to de-allocate an instance of IloFastMutex. This destructor is called automatically by the runtime system. The destructor releases operating system-specific resources of the invoking mutex.


isLocked

public int isLocked()

This member function returns a Boolean value that shows the state of the invoking mutex. That is, it tells you whether the mutex is locked by the calling thread (1) or unlocked (0) or locked by a thread other than the calling thread (also 0).


unlock

public void unlock()

This member function releases the lock on the invoking mutex, if there is such a lock.

If you call this member function on a mutex that has not been locked by the calling thread, then this member function throws an exception.