/************************************************** * Secondary threads main function * **************************************************/ void* DoNewThread(void* threadNumArg) { int threadNum = *((int*)threadNumArg); Print(roleStrings[threadNum] + " thread was created succesfully."); // FOR DEBUG IncThreads(); switch (threadNum) { case ROLE_WAIT: DoSleep(1000); ErrorExit(RES_EXIT_TIMEOUT); // the ROLE_WAIT thread reached its timeout of 1000 seconds - something is wrong case ROLE_LOOP: while (1); // never exits from here break; case ROLE_FINISH: break; // exits normally, process continues case ROLE_EXIT: if (exitType == EXIT_SEC_EXIT) { while (NumOfThreads() != ROLE_SIZE) { DoYield(); // wait here until all threads are ready } Print("ROLE_EXIT thread is calling exit()"); // FOR DEBUG // exit and kill the entire process exit(RES_SUCCESS); // never returns } // thread exits but process continues ThreadExit(); // never returns case ROLE_CANCELED: // On Windows, this thread will be canceled using the TerminateThread API. The documentation states that // it is unsafe to use this function if the target thread is executing certain kernel32 calls etc. // On Linux, the thread must enter a function which is defined as a cancellation point. See pthreads entry // in the chapter 7 of the manual for further details. readyToCancel = true; EnterSafeCancellationPoint(); } return NULL; }
void* DoDummyThread(void* dummy) { IncThreads(); DoYield(); return NULL; }
/************************************************** * Secondary threads' main functions * **************************************************/ void* DoExitThread(void* dummy) { Print("Exit thread is now going to exit"); IncThreads(); exit(RES_SUCCESS); }