Reputation: 9926
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 )
Upvotes: 11
Views: 2736
Reputation: 8071
That's not how lock works. You won't give anyone more "cpu time". If you're locking you might introduce wait periods and potentially deadlocks where the threads are waiting for each other.
Upvotes: 0
Reputation: 108830
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.
Upvotes: 14