Jump to content
  • Advertisement
Sign in to follow this  
MetaKnight

Make a thread wait?

This topic is 4553 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 am stopping two threads like so for each thread:
if(myState == NORMAL)
{
        InterlockedIncrement(&myState);
	//myState = STOPPED;
}
while(myState == STOPPED);

now this is for two threads, now when a third thread find thats both have stopped it starts them again like so:
if(Gary->myState == STOPPED && Zoey->myState == STOPPED )
{
	Gary->myState = NORMAL;
	Zoey->myState = NORMAL;
} 

The problem is that the while loop is stupid. But I dont know another way to do this. I could try sleep but too high would waste time, and too low would be the same as a while();. So what is the best way to make a thread "wait", but not doing any instructions so that the other thread can go faster.

Share this post


Link to post
Share on other sites
Advertisement
Event Objects were designed specifically to allow you to synchronize however you want. You can use the wait functions that 'Paulius Maruska' linked to to query (timeout = 0) or wait for an event to be set.

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!