Exemplo n.º 1
0
int kill_thread(int handle)
{
	Thread *thread = static_cast<Thread*>(GetResource(handle, OBJ_THREAD));
	if (thread == 0)
		return E_BAD_HANDLE;

	if (thread == Thread::GetRunningThread()) {
		thread->ReleaseRef();
		thread->Exit();
	} else {
		APC *apc = new APC;
		apc->fCallback = kill_apc;
		apc->fIsKernel = true;
		apc->fData = thread;
		thread->EnqueueAPC(apc);
		thread->ReleaseRef();
	}
	
	return E_NO_ERROR;
}
Exemplo n.º 2
0
// The Grim Reaper thread reclaims resources for threads and teams that
// have exited.
int Thread::GrimReaper(void*)
{
	for (;;) {
		fThreadsToReap.Wait();
		cpu_flags fl = DisableInterrupts();
		Thread *victim = static_cast<Thread*>(fReapQueue.Dequeue());
		RestoreInterrupts(fl);

		// The thread may not actually get deleted here if someone else has
		// a handle to it.
		victim->ReleaseRef();
	}
}