Does locking take CPU time?

I have 6 threads. One of the threads falls into a certain area and includes a "lock" and all other threads wait and want to enter the same area.

Now, will other threads get processor time? Does the other thread remain in the thread schedule? I understand that all the other thread is idle, but the processor will try to continue working and try to enter the area (even if the area is inaccessible)

+7
source share
2 answers

When you try to enter a lock that has already been made, the threads first spin for a while and finally pause and enter the wait state.

They still record CPU time while they are spinning, but no longer wait.

+10
source

This is not how the castle works. You won’t give anyone any more processor time. If you block, you can enter periods of waiting and potentially blocking, where threads are waiting for each other.

0
source

All Articles