Jump to content
  • Advertisement
Sign in to follow this  
coderWalker

C# .NET Mutex operations

This topic is 2310 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 having issues with the GUI Window of my program not responding.

I have a thread pool running doing calculations in the background and when they send their results to a middle ground they call "mutex.waitOne()" then they add their results to a middle ground and then "mutex.release()" upon completion.

I also have the same 2 lines in the mainGUI's code ( waitOne() and release() ) during a timer event that checks if more results have been added to the middle ground.

The problem is when the threads add their results to the middle ground it has to be sorted with the other data in the middle ground and it takes a while to release the mutex. While they are uploading their data the main GUI tries to access it at the same time and has to wait because of the mutex. Which is almost how I want it to work because 2 threads can not access the same data at the same time.

How can I make this more effecient?

I do not want the Window to stop responding at random and having to wait on the other threads.

Is it somehow possible that when the Main GUI thread trys to check the middle ground that the other threads could pause until it's done?

Any ideas welcome.

Thanks

CoderWalker

Share this post


Link to post
Share on other sites
Advertisement
Why don't you wait until all of the processing/sorting is done before writing it to the location that the UI picks it up?

Share this post


Link to post
Share on other sites

Why don't you wait until all of the processing/sorting is done before writing it to the location that the UI picks it up?


The problem is the middleground contains basically a tree of data. When a thread is done making it's calculations it has to go threw the trees and add it's results in the proper places. If something new was added it adds that result and location to a queue. When the GUI thread checks for new data it checks the queue.
So basically as of right now the function for adding the threads results and the function for checking for new results both access the same queue.

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!