Author: Tony Werten
Date: 01:10:35 12/01/03
Go up one level in this thread
On December 01, 2003 at 03:47:04, Hristo wrote: >On December 01, 2003 at 03:39:27, Russell Reagan 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 ? >> >>What language are you using? >> >>The Sleep() Win32 API > >duh ... he used the lower case "sleep()" so I thought, hoped, he was using unix >and Windows. Even worse, I use Delphi wich doesn't make a difference between sleep() and Sleep(). I didn't know there were 2. I'll first find out wich one ends up being called. Tony > >Regards, >Hristo > >>call might be a dirty solution. IIRC, the Sleep() function >>puts the calling thread to sleep for a specified number of milliseconds, so that >>thread shouldn't run during that time. I think Sleep() is different from >>sleep(). Also check out SleepEx(). It can do some extra things that might help >>you out. >> >>If you want to do it the "right" way, then you should probably use >>WaitForSingleObject() or WaitForMultipleObjects(), both Win32 API functions. I >>think these will only work if you use the Win32 threading stuff though. It's >>been a while since I've used them, but I think those functions will wait on any >>Windows handle (events, threads, files, etc.). >> >>If you use a different third party threading library and it doesn't provide this >>functionality, Sleep() might be a good solution. >> >>You might have a look at these: >> >>Process and Thread Functions (Sleep/SleepEx, among other interesting functions) >>http://msdn.microsoft.com/library/en-us/dllproc/base/process_and_thread_functions.asp >> >>Synchronization Functions (WaitFor*, among other interesting functions) >>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitforsingleobject.asp
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.