From 4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 13 Feb 2012 21:47:03 +0000 Subject: Rewritten most of the code for multithreading; still not 100%, but getting there. If this commit proves to be too problematic, we can always undo it. git-svn-id: http://mc-server.googlecode.com/svn/trunk@251 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cIsThread.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source/cIsThread.cpp') diff --git a/source/cIsThread.cpp b/source/cIsThread.cpp index 4aa25b534..3f4442f7f 100644 --- a/source/cIsThread.cpp +++ b/source/cIsThread.cpp @@ -67,6 +67,7 @@ cIsThread::cIsThread(const AString & iThreadName) : cIsThread::~cIsThread() { + mShouldTerminate = true; Wait(); } @@ -81,7 +82,7 @@ bool cIsThread::Start(void) // Create the thread suspended, so that the mHandle variable is valid in the thread procedure DWORD ThreadID = 0; - HANDLE mHandle = CreateThread(NULL, 0, thrExecute, this, CREATE_SUSPENDED, &ThreadID); + mHandle = CreateThread(NULL, 0, thrExecute, this, CREATE_SUSPENDED, &ThreadID); if (mHandle == NULL) { LOGERROR("ERROR: Could not create thread \"%s\", GLE = %d!", mThreadName.c_str(), GetLastError()); @@ -122,10 +123,12 @@ bool cIsThread::Wait(void) { return true; } - LOG("Waiting for thread \"%s\" to terminate.", mThreadName.c_str()); + // Cannot log, logger may already be stopped: + // LOG("Waiting for thread \"%s\" to terminate.", mThreadName.c_str()); int res = WaitForSingleObject(mHandle, INFINITE); mHandle = NULL; - LOG("Thread \"%s\" %s terminated, GLE = %d", mThreadName.c_str(), (res == WAIT_OBJECT_0) ? "" : "not", GetLastError()); + // Cannot log, logger may already be stopped: + // LOG("Thread \"%s\" %s terminated, GLE = %d", mThreadName.c_str(), (res == WAIT_OBJECT_0) ? "" : "not", GetLastError()); return (res == WAIT_OBJECT_0); #else // _WIN32 -- cgit v1.2.3