Thread.Sleep (0) will give up purchased CPU resource?

When I set the time interval to zero

static void Main()
{
   Thead.Sleep(0);
}

      

will the Main () thread give up on the cpu resource it acquired or not wait, will it continue?

+2


source to share


2 answers


Yes. The thread must be suspended for this loop, allowing other threads to access the CPU. The code will be immediately scheduled for the next cycle.

The thread will continue to process the next scheduled processor slot on it in a multi-threaded environment.



Thread.Sleep (-1) pauses the thread indefinitely.

+6


source


Thread.Sleep (0) only discards CPU resources for threads with equal or higher priority. If there is a thread pending with a lower priority, it will be ignored.



This is why Thread.Sleep (1) is recommended.

+4


source







All Articles