Sunday, May 3, 2009

How to force thread to perform context switch

What is a context switch?
A context switch is an action performed by operating systems to switch from one process/thread to another.
Basically, during application execution the operating system provides a CPU time for each thread.
While thread is executed its state is loaded into CPU registers.
By the time comes to execute a new thread, current's thread data is stored back in process's stack and a new process's state is loaded into CPU registers.

You can cause context switch by calling:

C/C++
  • Sleep(0);
C#
  • System.Threading.Thread.Sleep(0);

0 comments:

Post a Comment