#include #include #include using boost::interprocess::interprocess_semaphore; using namespace std; class threadA : public unary_function,void> { public: void operator ()(shared_ptr sem)const { cout << "a" << endl; sem->post(); } }; class threadB : public unary_function,void> { public: void operator ()(shared_ptr sem)const { sem->wait(); cout << "b" << endl; } }; int main() { using boost::thread; shared_ptr sem(new interprocess_semaphore(0)); thread a(threadA(), sem); thread b(threadB(), sem); a.join(); b.join(); }