Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 'Lock' taking CPU time?

Tags:

c#

.net

clr

I have 6 threads. One of the thread get in some scope and turn on the 'lock' and all the other threads are waiting and want to enter to the same scope.

Now, Is the other threads will get CPU Time? Does the other thread are in the thread schedule ? I understand that all the other thread are in waiting state - but the CPU will try to make the thread continue and try to get in the scope ( even if the scope is not accessible )

like image 279
Yanshof Avatar asked Feb 02 '23 08:02

Yanshof


1 Answers

When trying to enter a lock that's already taken, threads first spinlock for a while, and finally suspend and enter a wait state.

They still burn CPU time while they spin, but no longer once they wait.

like image 105
CodesInChaos Avatar answered Feb 13 '23 03:02

CodesInChaos