Ticket #4524: sem.cc

File sem.cc, 289 bytes (added by Gennady Proskurin <gprspb@…>, 12 years ago)

When main thread sleeps in sleep(), thread thr1 does wait() on semaphore and consumes cpu while waiting.

Line 
1#include <boost/interprocess/sync/interprocess_semaphore.hpp>
2#include <boost/thread/thread.hpp>
3#include <unistd.h>
4
5boost::interprocess::interprocess_semaphore sem(0);
6
7void thr1()
8{
9 sem.wait();
10}
11
12int main()
13{
14 boost::thread t1(thr1);
15 sleep(10);
16 sem.post();
17 t1.join();
18 return 0;
19}