Threading events and Intel Building Blocks
The Intel Threading Building Blocks library (TBB) is a useful cross-platform C++ library, which contains many high and low level tools for developing multi-threaded applications.
One feature I required but couldn’t find in TBB is a class similar to AutoResetEvent in the .NET framework. That class allows simple synchronization of two threads. One of them is waiting the event to be triggered, while the other triggers the event at a point.
I have implemented this class in C++, using atomic operations from TBB, which guaranties that if the two threads are running on different cores, then their caches get synced immediately when accessing the shared memory. Files:
- ThreadEvent.h (Contains code documentation)
- ThreadEvent.cpp
This is an example for the usage:
Notes:
- Read the documentation in ThreadEvent.h
- Can be used between two threads only, because of its auto reset property.
- If you want two-way communication between your threads, then use two objects.