bool FHelperThread::LaunchThread () { int i; MessageHead = MessageTail = 0; for (i = 0; i < MSG_QUEUE_SIZE; i++) { if ((Messages[i].CompletionEvent = CreateEvent (NULL, FALSE, i > 0, NULL)) == NULL) break; } if (i < MSG_QUEUE_SIZE) { for (; i >= 0; i--) { CloseHandle (Messages[i].CompletionEvent); } return false; } InitializeCriticalSection (&Thread_Critical); if ((Thread_Events[0] = CreateEvent (NULL, TRUE, FALSE, NULL))) { if ((Thread_Events[1] = CreateEvent (NULL, TRUE, FALSE, NULL))) { if ((ThreadHandle = CreateThread (NULL, 0, ThreadLaunch, (LPVOID)this, 0, &ThreadID))) { HANDLE waiters[2] = { Messages[0].CompletionEvent, ThreadHandle }; if (WaitForMultipleObjects (2, waiters, FALSE, INFINITE) == WAIT_OBJECT_0+1) { // Init failed, and the thread exited DestroyThread (); return false; } #if defined(_MSC_VER) && defined(_DEBUG) // Give the thread a name in the debugger struct { DWORD type; LPCSTR name; DWORD threadID; DWORD flags; } info = { 0x1000, ThreadName(), ThreadID, 0 }; __try { RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (ULONG_PTR *)&info ); } __except(EXCEPTION_CONTINUE_EXECUTION) { } #endif return true; } CloseHandle (Thread_Events[1]); } CloseHandle (Thread_Events[0]); }
Thread CreateThread_SDL (ThreadFunction func, void *data, SDWORD stackSize #ifdef NAMED_SYNCHRO , const char *name #endif ) { TrueThread thread; struct ThreadStartInfo *startInfo; thread = (struct _thread *) HMalloc (sizeof *thread); #ifdef NAMED_SYNCHRO thread->name = name; #endif #ifdef PROFILE_THREADS thread->startTime = GetTimeCounter (); #endif thread->localData = CreateThreadLocal (); startInfo = (struct ThreadStartInfo *) HMalloc (sizeof (*startInfo)); startInfo->func = func; startInfo->data = data; startInfo->sem = SDL_CreateSemaphore (0); startInfo->thread = thread; thread->native = SDL_CreateThread (ThreadHelper, (void *) startInfo); if (!(thread->native)) { DestroyThreadLocal (thread->localData); HFree (startInfo); HFree (thread); return NULL; } // The responsibility to free 'startInfo' and 'thread' is now by the new // thread. QueueThread (thread); #ifdef DEBUG_THREADS #if 0 log_add (log_Debug, "Thread '%s' created.", ThreadName (thread)); fflush (stderr); #endif #endif // Signal to the new thread that the thread structure is ready // and it can begin to use it. SDL_SemPost (startInfo->sem); (void) stackSize; /* Satisfying compiler (unused parameter) */ return thread; }
void CThreadBase::DoRunThreadL() { CActiveScheduler* scheduler = NULL; scheduler = new (ELeave) CActiveScheduler; CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); OpenSemaphore(); SetUpTestL( ThreadName() ); ThreadL(); TakeDownTest(); CloseSemaphore(); CleanupStack::PopAndDestroy(scheduler); }
void CThreadBase::Go() { iThread.Create( ThreadName(), CThreadBase::ThreadFunction, KDefaultStackSize, 0x2000, 0x20000, this ); iThread.Logon( iThreadStatus ); iThread.Resume(); }