Sign in to follow this  
Sync Views

Multi-threading

Recommended Posts

How can I tell if a thread is still running or not? I'm creadting my threads with the code below. The problem is once Ive started the shutdown (the main thread sets a global bool to false, the other threads just check it at certain points) I don't want the main thread to exit until after the other ones have finished. eg saving data, sending server shutdown messages to connect clients, etc.
	//create gui thread
	unsigned int GuiId;
	uintptr_t GuiThread = _beginthreadex(
		NULL,
		0,
		GuiMain,
		(void*)hInstance,
		0,
		&GuiId);
	unsigned int NetId;
	//create net thread
	uintptr_t NetThread = _beginthreadex(
		NULL,
		0,
		NetMain,
		NULL,
		0,
		&NetId);

Share this post


Link to post
Share on other sites
What you want is called a join. Most threading libraries will support this synchronization operation afaik. I would recommend looking into Boost.Threads for easy cross platform threaded development.

Share this post


Link to post
Share on other sites
The thread handle can act as an event object. After you have set the global variable telling the thread to shutdown, call WaitForSingleObject(threadHandle, INFINITE);

There's a sample in msdn:
http://msdn2.microsoft.com/en-us/library/kdzttdcb(VS.71).aspx

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