views:

257

answers:

2

Hi,

i have alot of spin locks in my multithread code and most of the time they are waiting for other threads to do work and thus chew alot of cpu usage. In linux i normally use pthread_cond_wait and pthread_cond_signal to pause a thread and wake up when signaled. Is there something like this in the boost libraries? Having a quick look i couldnt find any thing.

Visual studio 2005

+1  A: 

You are looking for a Mutex or a Semaphore. The Boost library does have Mutex and Semaphore support.

A Mutex is a Binary Semaphore, which is simply thought of as a lock, allowing only one thread to go through your critical section.

Counting semaphores can help to simplify some situations where a lock(Mutex) is too restrictive.

Kekoa
Nupe, i was after a Condition Variables
Lodle
+4  A: 

Found it, boost calls them condition variables: http://www.boost.org/doc/libs/1_39_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref

Lodle