void do_test_condition_notify_all() { const int NUMTHREADS = 3; boost::interprocess::ipcdetail::OS_thread_t thgroup[NUMTHREADS]; condition_test_data<Condition, Mutex> data; for(int i = 0; i< NUMTHREADS; ++i){ boost::interprocess::ipcdetail::thread_launch(thgroup[i], bind_function(&condition_test_thread<Condition, Mutex>, &data)); } //Make sure all threads are blocked boost::interprocess::ipcdetail::thread_sleep(1000); { boost::interprocess::scoped_lock<Mutex> lock(data.mutex); BOOST_INTERPROCESS_CHECK(lock ? true : false); data.notified++; } data.condition.notify_all(); for(int i = 0; i< NUMTHREADS; ++i){ boost::interprocess::ipcdetail::thread_join(thgroup[i]); } BOOST_INTERPROCESS_CHECK(data.awoken == NUMTHREADS); }
static int register_function (lua_State *L) { const char* fnname = luaL_checkstring(L, 1); // old code using aliases //const char* fmt="luabash call %s "; //char* fullname=(char*) malloc(strlen(fmt)+strlen(fnname)); //sprintf(fullname, fmt, fnname); //add_alias(fnname, fullname); WORD_LIST* wluabash=(WORD_LIST*) malloc(sizeof(WORD_LIST)); WORD_LIST* wcall=(WORD_LIST*) malloc(sizeof(WORD_LIST)); WORD_LIST* wfnname=(WORD_LIST*) malloc(sizeof(WORD_LIST)); WORD_LIST* warguments=(WORD_LIST*) malloc(sizeof(WORD_LIST)); wluabash->next = wcall; wcall->next=wfnname; wfnname->next=warguments; warguments->next=0; wluabash->word=make_word("luabash"); wcall->word=make_word("call"); wfnname->word=make_word(fnname); warguments->word=make_word("$@"); SIMPLE_COM* call_luabash=newSimpleCom(wluabash); COMMAND* function_body=make_command(cm_simple, call_luabash); bind_function(fnname,function_body); return 0; }
void do_test_condition_notify_one() { condition_test_data<Condition, Mutex> data; boost::thread thread(bind_function(&condition_test_thread<Condition, Mutex>, &data)); { boost::interprocess::scoped_lock<Mutex> lock(data.mutex); assert(lock ? true : false); data.notified++; data.condition.notify_one(); } thread.join(); assert(data.awoken == 1); }
void do_test_condition_waits() { condition_test_data<Condition, Mutex> data; boost::interprocess::ipcdetail::OS_thread_t thread; boost::interprocess::ipcdetail::thread_launch(thread, bind_function(&condition_test_waits<Condition, Mutex>, &data)); { boost::interprocess::scoped_lock<Mutex> lock(data.mutex); BOOST_INTERPROCESS_CHECK(lock ? true : false); boost::interprocess::ipcdetail::thread_sleep(1000); data.notified++; data.condition.notify_one(); while (data.awoken != 1) data.condition.wait(lock); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data.awoken == 1); boost::interprocess::ipcdetail::thread_sleep(1000); data.notified++; data.condition.notify_one(); while (data.awoken != 2) data.condition.wait(lock); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data.awoken == 2); boost::interprocess::ipcdetail::thread_sleep(1000); data.notified++; data.condition.notify_one(); while (data.awoken != 3) data.condition.wait(lock); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data.awoken == 3); boost::interprocess::ipcdetail::thread_sleep(1000); data.notified++; data.condition.notify_one(); while (data.awoken != 4) data.condition.wait(lock); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data.awoken == 4); } boost::interprocess::ipcdetail::thread_join(thread); BOOST_INTERPROCESS_CHECK(data.awoken == 4); }
void do_test_condition_waits() { condition_test_data<Condition, Mutex> data; boost::thread thread(bind_function(&condition_test_waits<Condition, Mutex>, &data)); { boost::interprocess::scoped_lock<Mutex> lock(data.mutex); assert(lock ? true : false); boost::thread::sleep(delay(1)); data.notified++; data.condition.notify_one(); while (data.awoken != 1) data.condition.wait(lock); assert(lock ? true : false); assert(data.awoken == 1); boost::thread::sleep(delay(1)); data.notified++; data.condition.notify_one(); while (data.awoken != 2) data.condition.wait(lock); assert(lock ? true : false); assert(data.awoken == 2); boost::thread::sleep(delay(1)); data.notified++; data.condition.notify_one(); while (data.awoken != 3) data.condition.wait(lock); assert(lock ? true : false); assert(data.awoken == 3); boost::thread::sleep(delay(1)); data.notified++; data.condition.notify_one(); while (data.awoken != 4) data.condition.wait(lock); assert(lock ? true : false); assert(data.awoken == 4); } thread.join(); assert(data.awoken == 4); }
void do_test_condition_notify_one() { condition_test_data<Condition, Mutex> data; boost::interprocess::ipcdetail::OS_thread_t thread; boost::interprocess::ipcdetail::thread_launch(thread, bind_function(&condition_test_thread<Condition, Mutex>, &data)); //Make sure thread is blocked boost::interprocess::ipcdetail::thread_sleep(1000); { boost::interprocess::scoped_lock<Mutex> lock(data.mutex); BOOST_INTERPROCESS_CHECK(lock ? true : false); data.notified++; data.condition.notify_one(); } boost::interprocess::ipcdetail::thread_join(thread); BOOST_INTERPROCESS_CHECK(data.awoken == 1); }
void do_test_condition_notify_all() { const int NUMTHREADS = 3; boost::thread_group threads; condition_test_data<Condition, Mutex> data; for (int i = 0; i < NUMTHREADS; ++i) threads.create_thread(bind_function(&condition_test_thread<Condition, Mutex>, &data)); { boost::interprocess::scoped_lock<Mutex> lock(data.mutex); assert(lock ? true : false); data.notified++; data.condition.notify_all(); } threads.join_all(); assert(data.awoken == NUMTHREADS); }