Jump to content
  • Advertisement
Sign in to follow this  
Laval B

Win32 event and thread API question

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

Hello everyone

I ran into a little problem using win32 event api. I have threads that are blocked on an event. When some job is ready to be executed, the event is signaled (using SetEvent). Jobs are placed in a shared queue.

According to Microsoft documentation, one of the waiting threads will wake and the event will be reset (autoreset event). The problem i have is that if no thread is wating because they are all busy, the event will be lost and when they go back waiting, none of them will ever know about the new job.

Is there a way to solve that problem ?

Share this post


Link to post
Share on other sites
Advertisement
A missed event is a common problem when not using a lock acquisition system.

The article "Solving 11 likely problems in your multithreaded code" discusses it about 3/4 of the way through, and includes links to several other articles that provide solutions.

Multithreading is hard to do correctly. There is no tutorial you can use, no block of code you can copy, that will give you solid concurrent code. You need to have a complete mindset of concurrency that is used through the entire code base.

Share this post


Link to post
Share on other sites

Multithreading is hard to do correctly. There is no tutorial you can use, no block of code you can copy, that will give you solid concurrent code. You need to have a complete mindset of concurrency that is used through the entire code base.


Yes, i realize that and this is what i'm trying to get. Thank you very much for the reference.

Share this post


Link to post
Share on other sites
I'm now using a semaphore instead of an event. That way, even if the thread is processing, the semaphore still gets incremented and when it calls WaitForSingleObject again, if the count isn't back to zero, it will process otherwise, it will go back to sleep. Edited by Laval B

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!