|
-
Apr 9th, 2024, 11:36 AM
#1
[RESOLVED] Thread Is Too Fast
I have to run off somewhere, and I haven't had enough time to think about this issue, so I thought I'd toss out a problem in search of a better solution. It's a good problem to have, too.
I wrote a program back around 2003/2005 that...had a LOT of iterations, each of which took a stately amount of time. The result was that the program would take roughly 1.5 days to run to completion. Just recently, I decided to dust off that project and bring it into the modern age. Computers are faster these days, there are more cores, and the program is an example of an embarrassingly parallel application. It REALLY could benefit from threading on multiple cores. No thread will be waiting for any length of time, so threading on a single core never made sense, but threading on multiple cores makes LOTS of sense.
So, I got it working, and have found that it runs too fast. Not a bad problem to have, really, but it messes with the interface. The program is a genetic algorithm. It goes through many thousands of generations in a run. Previously, it went fast enough that it looked pretty good, but the user would be able to use some tools to visualize the evolution over time. Now, it's just too fast, so I'm considering how to change the interface such that the user can still visualize things.
One piece of that is that I need a means to pause a thread. The main loop is running in a BackGroundWorker. My first thought is that I could run that loop inside a sync block. The first step of the loop could be to lock an object, which would then be released at the end of the loop. Of course, this would mean that the lock would be reacquired almost immediately, but there would be an instruction or two during which it would be released. If some of the UI actions wanted to pause the loop, they could also lock that object. This seems like it would work. So long as the UI element held the lock, the BGW would not be able to loop. Once the UI element released the lock, the loop would continue.
Is there any issue with that approach, and is there any other approach I ought to consider to temporarily suspend a thread?
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|