Sign in to follow this  
Skyd168

SDL_WaitThread invalid handle??

Recommended Posts

Is there anyway to check and see if an SDL_Thread is still running? I'm writing a video player that uses threads. The stop() function uses SDL_WaitThread to make sure all the buffering threads and whatnot are stopped. The problem occurs if a person calls the stop() function twice in a row. Since no threads are running after the 1st call, the second call returns with an "An invalid handle was specified" error with the debugger pointing at the SDL_WaitThread line. Here's my stop method:
bool VideoPlayer::stop()
{
	isPlaying = false;
	isBuffering = false;
	SDL_WaitThread(bufferer, NULL);
	SDL_WaitThread(player, NULL);
	pCodec->seekTo(0);
	clearBuffer(&frontBuffer);
	clearBuffer(&backBuffer);
	pDisplay->clearScreen();
	return true;
}

Here is how I created my threads
bool VideoPlayer::play(video::PlayMode pMode)
{
	if (!isPlaying)
	{
		playMode = pMode;
		isBuffering = true;
		isPlaying = true;
		bufferer = SDL_CreateThread(buffer_thread, this);
		player = SDL_CreateThread(play_thread, this);
		return true;
	}
	return false;
}

Any ideas??

Share this post


Link to post
Share on other sites
The SDL Manual isn't very clear about this. But it seems that if you try to get the id of a thread that's already terminated , SDL_GetThreadID() will return 0. Use this to check whether they've terminated or not...

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