int main() { state = START; boost::thread thrda(&player, PLAYER_A); boost::thread thrdb(&player, PLAYER_B); boost::xtime xt; boost::xtime_get(&xt, boost::TIME_UTC_); xt.sec += 1; boost::thread::sleep(xt); { boost::unique_lock<boost::mutex> lock(mutex); std::cout << "---Noise ON..." << std::endl; } for (int i = 0; i < 10; ++i) cond.notify_all(); { boost::unique_lock<boost::mutex> lock(mutex); std::cout << "---Noise OFF..." << std::endl; state = GAME_OVER; cond.notify_all(); do { cond.wait(lock); } while (state != BOTH_PLAYERS_GONE); } std::cout << "GAME OVER" << std::endl; thrda.join(); thrdb.join(); return 0; }
int main(int argc, char* argv[]) { state = START; boost::thread thrda(thread_adapter(&player, (void*)PLAYER_A)); boost::thread thrdb(thread_adapter(&player, (void*)PLAYER_B)); boost::xtime xt; boost::xtime_get(&xt, boost::TIME_UTC); xt.sec += 1; boost::thread::sleep(xt); { boost::mutex::scoped_lock lock(mutex); std::cout << "---Noise ON..." << std::endl; } for (int i = 0; i < 1000000; ++i) cond.notify_all(); { boost::mutex::scoped_lock lock(mutex); std::cout << "---Noise OFF..." << std::endl; state = GAME_OVER; cond.notify_all(); do { cond.wait(lock); } while (state != BOTH_PLAYERS_GONE); } std::cout << "GAME OVER" << std::endl; thrda.join(); thrdb.join(); return 0; }