Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

Multi-threading

This topic is 3891 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!