Search code examples
windowsmultithreadingcontext-switch

Forcing context switch in Windows


Is there a way to force a context switch in C++ to a specific thread, assuming I have the thread handle or thread ID?


Solution

  • No, you won't be able to force operating system to run the thread you want. You can use yield to force a context switch though...

    yield in Win32 API is function SwitchToThread. If there is no other thread available for running, then a ZERO value will be returned and current thread will keep running anyway.