Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 210
Idov Avatar asked Mar 02 '26 04:03

Idov


1 Answers

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.

like image 118
Pablo Santa Cruz Avatar answered Mar 05 '26 02:03

Pablo Santa Cruz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!