views:

38

answers:

1

The disadvantage would be in comparison to a technique that was specialized to work on threads that are running within the same process. For example, does wait/post cause the whole process to yield, rather than just the executing thread, even though anyone waiting for a post would be within the same process?

The semaphore would be used, for example, to solve a producer/consumer problem in a shared buffer between two threads in the same process.

Are there any reasonable alternatives?

+2  A: 

Use Boost.Thread condition variables as shown here. The accompanying article has a good summary of Boost.Thread features.

Using interprocess semaphores will work but it's likely to place a tax on your execution due to use of unnecessarily heavyweight underlying OS locking primitives (named kernel objects in Windows, for example).

Steve Townsend