841 名前:デフォルトの名無しさん mailto:sage [2012/02/11(土) 16:10:52.17 ] 待つだけでいいならミューテックスでもいいのでは…そういう話ではない…? #include <iostream> #include <boost/thread.hpp> #include <unistd.h> void f( boost::mutex* guard ) { std::cout << "worker: working" << std::endl; std::cout << "worker: waiting until the mutex was unlocked" << std::endl; guard->lock(); std::cout << "worker: finished" << std::endl; guard->unlock(); } int main() { boost::mutex m; std::cout << "main: lock a mutex" << std::endl; m.lock(); std::cout << "main: create a worker" << std::endl; boost::thread worker(&f,&m); std::cout << "main: sleeping 3 seconds" << std::endl; sleep(3); std::cout << "main: unlock the mutex" << std::endl; m.unlock(); std::cout << "main: waiting for join" << std::endl; worker.join(); std::cout << "main: finished" << std::endl; return 0; } $ ./sample main: lock a mutex main: create a worker main: sleeping 3 seconds worker: working worker: waiting until the mutex was unlocked main: unlock the mutex main: waiting for join worker: finished main: finished