yield execution to another process in windows

3c6597370b476903ed475f70b4b3ce31
0
john 102 Jan 18, 2007 at 07:45

How do you tell the OS in windows to process another thread or process, which is useful when your app is processor-extensive? Sort of like the DoEvents in Visual Basic. I’m sure there is a Win32 API for that. Tried searching, but couldn’t find anything.

2 Replies

Please log in or register to post a reply.

Fdbdc4176840d77fe6a8deca457595ab
0
dk 158 Jan 18, 2007 at 07:51

There’s an API called SwitchToThread()

You could also call Sleep(0), which should yield to any thread that has the same or higher priority.

6d318bb67270aa12b325e2cd7b64ff7a
0
pater 101 Jan 18, 2007 at 21:01

Or, if you need to perform longer cpu-power expensive tasks (but nothing time-critical), you could also just lower your own process or task priority. That way, you can get as much CPU time as you want, without disturbing any other process/thread. All applications will stay responsive and act as if nothing was special, but you can use all the “idle” time without you having to periodically call Sleep().