
Hi, I need to synchronize 2 threads, that is once one is done doing something, it should activate another thread that had been waiting in a pending state. I see the thread library offers mutexes and nothing else. I guess mutexes would do, but I do not believe I should use mutexes for my application. Mutexes are supposed to provide mutual exclusion when critical data is accessed. Semaphores should be used for what I want to do. However, I only see semaphores available in the interprocess library. I only need inter-thread synchronization, and going the long way with the interprocess library seems a bit overkill. It may be an ideology issue here. I would appreciate your comments on what to use in this case. Thanks, Jean

Jean-Sebastien Stoezel wrote:
Hi,
I need to synchronize 2 threads, that is once one is done doing something, it should activate another thread that had been waiting in a pending state. I see the thread library offers mutexes and nothing else. I guess mutexes would do, but I do not believe I should use mutexes for my application. Mutexes are supposed to provide mutual exclusion when critical data is accessed. Semaphores should be used for what I want to do.
You can use condition variables for signalling: http://www.boost.org/doc/libs/1_38_0/doc/html/thread/synchronization.html#th... -- Sohail Somani http://uint32t.blogspot.com

Thanks for the quick reply. Using conditon variables sounds quite heavy. You need to instantiate a mutex, a condition variable and a flag... Would there be anything wrong with instantiating a semaphore from the interprocess library to provide inter-thread synchronization? By the way, why isn't there any semaphore available in the thread library? Jean On 2-Apr-09, at 9:25 PM, Sohail Somani wrote:
Jean-Sebastien Stoezel wrote:
Hi,
I need to synchronize 2 threads, that is once one is done doing something, it should activate another thread that had been waiting in a pending state. I see the thread library offers mutexes and nothing else. I guess mutexes would do, but I do not believe I should use mutexes for my application. Mutexes are supposed to provide mutual exclusion when critical data is accessed. Semaphores should be used for what I want to do.
You can use condition variables for signalling:
http://www.boost.org/doc/libs/1_38_0/doc/html/thread/synchronization.html#th...
-- Sohail Somani http://uint32t.blogspot.com
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

A barrier, maybe? On Thu, Apr 2, 2009 at 7:57 PM, Jean-Sebastien Stoezel <js.stoezel@gmail.com> wrote:
Thanks for the quick reply. Using conditon variables sounds quite heavy. You need to instantiate a mutex, a condition variable and a flag... Would there be anything wrong with instantiating a semaphore from the interprocess library to provide inter-thread synchronization? By the way, why isn't there any semaphore available in the thread library?

Jean-Sebastien Stoezel wrote:
Thanks for the quick reply. Using conditon variables sounds quite heavy. You need to instantiate a mutex, a condition variable and a flag... Would there be anything wrong with instantiating a semaphore from the interprocess library to provide inter-thread synchronization? You can use a semaphore from the interprocess library to provide inter-thread synchronization. An interprocess semaphore is a thin wrapper around a posix semaphore if BOOST_INTERPROCESS_POSIX_SEMAPHORES is defined. Otherwise, a semaphore is emulated with a mutex and a condvar.
By the way, why isn't there any semaphore available in the thread library?
The boost.Crypto library is going to provide some. BR, Dmitry

Interesting, thanks for the explanaition. On 3-Apr-09, at 5:27 AM, Dmitry Goncharov wrote:
Jean-Sebastien Stoezel wrote:
Thanks for the quick reply. Using conditon variables sounds quite heavy. You need to instantiate a mutex, a condition variable and a flag... Would there be anything wrong with instantiating a semaphore from the interprocess library to provide inter-thread synchronization? You can use a semaphore from the interprocess library to provide inter-thread synchronization. An interprocess semaphore is a thin wrapper around a posix semaphore if BOOST_INTERPROCESS_POSIX_SEMAPHORES is defined. Otherwise, a semaphore is emulated with a mutex and a condvar.
By the way, why isn't there any semaphore available in the thread library?
The boost.Crypto library is going to provide some.
BR, Dmitry _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (4)
-
Dmitry Goncharov
-
Jean-Sebastien Stoezel
-
Oliver Seiler
-
Sohail Somani