NO FRAMES

Class IloBarrier

Definition file: ilconcert/ilothread.h
A system class to synchronize threads at a specified number.

The class IloBarrier provides synchronization primitives adapted to Concert Technology. A barrier, an instance of this class, serves as a rendezvous for a specific number of threads. After you create a barrier for n threads, the first n-1 threads to reach that barrier will be blocked. The nth thread to arrive at the barrier completes the synchronization and wakes up the n-1 threads already waiting at that barrier. When the nth thread arrives, the barrier resets itself. Any other thread that arrives at this point is blocked and will participate in a new barrier of size n.

See ILOUSEMT for details about the compilation macro to use with instances of this class.

Note
The class IloBarrier has nothing to do with the ILOG CPLEX barrier optimizer.

System Class

IloBarrier 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 a Concert Technology environment are managed by an instance of IloEnv.

However, system classes, such as IloBarrier, differ from that Concert Technology pattern. IloBarrier is an ordinary C++ class. Its instances are allocated on the C++ heap.

Instances of IloBarrier are not automatically de-allocated by a call to IloEnv::end. You must explicitly destroy instances of IloBarrier by means of a call to the delete operator (which calls the appropriate destructor) when your application no longer needs instances of this class.

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

For example, it is not a good idea to make an instance of IloBarrier part of a conventional Concert Technology model allocated in a 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 IloBarrier

Instances of IloBarrier differ from the usual Concert Technology objects because they are not allocated in a Concert Technology environment, and their de-allocation is not managed automatically for you by IloEnv::end. Instead, you must explicitly destroy instances of IloBarrier by calling the delete operator when your application no longer needs those objects.

See Also:

Constructor Summary
public IloBarrier(int count)
Method Summary
public intwait()
Constructor Detail

IloBarrier

public IloBarrier(int count)

This constructor creates an instance of IloBarrier of size count and allocates it on the C++ heap (not in a Concert Technology environment).


Method Detail

wait

public int wait()

The first count-1 calls to this member function block the calling thread. The last call (that is, the call numbered count) wakes up all the count-1 waiting threads. Once a thread has been woken up, it leaves the barrier. When a thread leaves the barrier (that is, when it returns from the wait call), it will return either 1 (one) or 0 (zero). If the thread returns 0, the barrier is not yet empty. If the thread returns 1, it was the last thread at the barrier.

A nonempty barrier contains blocked threads or exiting threads.