Jump to content
  • Advertisement
Sign in to follow this  
icecubeflower

threads and semaphores

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

Semaphores are for keeping two threads from accessing the same data at the same time. Suppose I have a main function with a bool value and I pass it to a thread so both the main thread and the new thread both have access to that bool. The spawned thread can change that bool from false to true. Suppose I want my main thread to display something when that bool is changed to true. Is it necessary to put semaphores around wherever the threads access the bool? The main thread will never alter the bool, it only reads it. Is it risky that the main thread will be reading the bool while the spawned thread is in the middle of changing it from false to true? Is that even possible? Does it matter?

Share this post


Link to post
Share on other sites
Advertisement
It sounds like you need to read about condition variables. Now, I'm not aware of any architecture where reading or writing a bool is not atomic, but depending on how you wait for the bool to become true, you may end up wasting a lot of processor time.

Share this post


Link to post
Share on other sites
It won't waste much time. It's in the drawing loop. Draws a kabillion textured rectangles. If the bool is true then a few of the rectangles will be highlighted green.

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!