KDint KD_APIENTRY kdMain(KDint argc, const KDchar *const *argv) { test_once_count = kdAtomicIntCreateVEN(0); KDThread *threads[THREAD_COUNT] = {KD_NULL}; for(KDint i = 0; i < THREAD_COUNT; i++) { threads[i] = kdThreadCreate(KD_NULL, test_func, KD_NULL); if(threads[i] == KD_NULL) { if(kdGetError() == KD_ENOSYS) { return 0; } TEST_FAIL(); } } for(KDint k = 0; k < THREAD_COUNT; k++) { kdThreadJoin(threads[k], KD_NULL); } TEST_EQ(kdAtomicIntLoadVEN(test_once_count), 1); kdAtomicIntFreeVEN(test_once_count); return 0; }
// Lazy create semaphore & mutex & thread KDbool CCHttpClient::lazyInitThreadSemphore ( KDvoid ) { if ( l_pRequestQueue != KD_NULL ) { return KD_TRUE; } else { l_pRequestQueue = new CCArray ( ); l_pRequestQueue->init ( ); l_pResponseQueue = new CCArray ( ); l_pResponseQueue->init ( ); l_pRequestQueueMutex = kdThreadMutexCreate ( KD_NULL ); l_pResponseQueueMutex = kdThreadMutexCreate ( KD_NULL ); l_pSleepMutex = kdThreadMutexCreate ( KD_NULL ); l_pSleepCondition = kdThreadCondCreate ( KD_NULL ); l_pNetworkThread = kdThreadCreate ( KD_NULL, networkThread, KD_NULL ); kdThreadDetach ( l_pNetworkThread ); l_bNeedQuit = KD_FALSE; } return KD_TRUE; }