Author: Robert Hyatt
Date: 07:48:07 12/01/03
Go up one level in this thread
On December 01, 2003 at 04:55:31, Tony Werten wrote:
>On December 01, 2003 at 04:50:20, Andreas Guettinger wrote:
>
>>On December 01, 2003 at 02:41:28, Tony Werten wrote:
>>
>>>When my masterthread is spinning, waiting for results from it's workers threads,
>>>how do I keep it from burning CPU time ?
>>>
>>>The apifunction sleep() doesn't some threadsafe, suspending the thread and
>>>having it resumed by the worker seems overly complicated. ( Accept maybe if I
>>>can use a callback function )
>>>
>>>Any thoughts ?
>>>
>>>Tony
>>
>>Isn't that what condition variables are for?
>
>Yes, but the looping costs processor time. I want to get rid of that.
First, condition variables do _not_ loop. The wait for condition blocks.
Second, you are paranoid about not spinning. If a thread is not running,
you are wasting the _same_ compute cycles as nothing else is on the machine
during an imporant game, I hope. And any cycle you don't burn is forever
lost.
>
>Preferably:
>
>While (no_results) do request('Dear mr Operating System. Don't spend any time on
>me since I'm not doing anything usefull anyway. Please spend the remaining of
>this timeslice on my workers since I can't do anything until they are finished.
>Your's truly, Main Thread' :)
>
>Tony
You can always add a "sched_yield()" type call to your spin loop if you
insist. That says "move me to the end of the run queue and run something
else if you have something to run, otherwise come right back to me." But
why you'd want to do that is beyond me...
>
>>
>>regards
>>Andy
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.