Jump to content
  • Advertisement
Sign in to follow this  
ZealousEngine

How to tell if a boost::thread is sleeping?

This topic is 3917 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 ptr to a boost::thread, which is running its own little internal loop every x seconds, then goes to sleep for x seconds. I want the main thread to be able to query this thread and ask it if it is sleeping or awake/running. Is this possible? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Ah so there is no query built into boost thread? I have to use bools to monitor it?

But isnt it possible the main thread will query the sleep bool RIGHT after it is set to sleeping, but a microsecond before the thread actually goes to sleep?

*for my purposes I dont think it will matter, just curious if its possible

Share this post


Link to post
Share on other sites
Quote:
Original post by ZealousEngine
But isnt it possible the main thread will query the sleep bool RIGHT after it is set to sleeping, but a microsecond before the thread actually goes to sleep?

Yes, and this is why you should not count on such a thing. What are you trying to accomplish by finding this out?

Share this post


Link to post
Share on other sites
In that case, just do the boolean thing. It won't be exact, but then it's not possible for anything to be. Also, keep in mind that if you do it this way, what you will be testing is not how often the thread is sleeping, but how often the thread is sleeping while the main thread is executing. The two may be very different.

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!