Jump to content
  • Advertisement
Sign in to follow this  

Background thread just... vanishes

This topic is 3118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
{
protected:
	HANDLE  threadHandle;
	DWORD   threadID;

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

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

		// Start the thread.
		threadHandle = CreateThread( NULL,
			0,
			(LPTHREAD_START_ROUTINE)cThreadProc,
			this,
			0,
			(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
public:
	virtual DWORD threadProc()
	{
		while(1)
		{
		//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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!