Another interesting one is the ACE_Condition template. By using an ACE_Condition you can have your code wait for an arbitrary condition to occur. That condition is "embodied" in a variable of your choice. That variable can, in turn, be any data type you wish. This makes ACE_Condition much more flexible than a simple mutex, barrier or semaphore.
In this tutorial, I'll create a wrapper class around the ACE_Condition and the assorted housekeeping items necessary to make it work. I'll use a simple integer as the condition variable but keep in mind that you can use any data type you want.
Kirthika's abstract:
Pizza-delivery metaphor: (courtesy Dr.Schmidt)
This tutorial makes use of a wrapper class around the ACE_Condition and uses a integer value as the condition. The four kinds of condition implemented are: !=, >=, <=, == by using C++ operator overloading. Guards are used within the methods to make sure that the method is thread-safe. Once the thread completes its job, it broadcasts to the waiting on it.
An ACE_Task is used to stress test the various conditions. A test object is created for each condition and the main thread waits until the condition becomes true. For instance: <= condition: Five threads are spwaned which in turn increment the condition variable, which is initialised to 1 by 2. Remember that you are waiting on the <= condition. So once 3 threads have been thru it, the value becomes 6 and the condition becomes true!
This simple example shows us how to program and use the Condition variable for synchronisation.