Sign in to follow this  

Background thread just... vanishes

Recommended Posts

I have a background thread running in my game, and my problem is it just vanishes after the first few seconds. I'm on a dual core windows XP machine.
class ThreadClass
	HANDLE  threadHandle;
	DWORD   threadID;

	ThreadClass() : threadHandle(NULL), threadID(0) {	}
	virtual ~ThreadClass() { end(); }

	void begin()
		if( threadHandle )
			end();  // just to be safe.

		// Start the thread.
		threadHandle = CreateThread( NULL,
			(LPDWORD)&threadID );
		if( threadHandle == NULL )		{
			// Arrooga! Dive, dive!  And deal with the error, too!

//		SetThreadPriority(threadHandle, THREAD_PRIORITY_LOWEST);
		SetThreadPriority(threadHandle, THREAD_PRIORITY_BELOW_NORMAL);
//		SetThreadPriority(threadHandle, THREAD_PRIORITY_NORMAL);

	void end()
		//----------a breakpoint here never gets called
		if( threadHandle != NULL )
			WaitForSingleObject( threadHandle, INFINITE );
			CloseHandle( threadHandle );
			threadHandle = NULL;

	virtual DWORD threadProc() = 0;

static DWORD WINAPI cThreadProc( ThreadClass* pThis ) {
	return pThis->threadProc();

and then a basic class inherits from it :
class ThreadGrouper : public ThreadClass
//stuff here
	virtual DWORD threadProc()
		//mainloop stuff
		//--------a breakpoint here never gets called
		return 0;
The stuff in the while loop runs for a bit at startup, then its just gone and putting a breakpoint in gets nothing. the end() function never gets called, so I have no idea what is happening, or how to debug it. Could anyone point me in the right direction?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this