top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Spinlocks should be avoided in uniprocessor contexts. Why is this?

+3 votes
654 views
Spinlocks should be avoided in uniprocessor contexts. Why is this?
posted Dec 2, 2014 by Bheemappa G

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

There is no point in spinning to wait for a resource in a uniprocessor system, because you will may as well switch threads sooner rather than later. Whereas on a multiprocessor system, a thread on another processor may release the lock without you context-switching. Spinlocks can be useful, then, if you don't expect to be waiting long, because it may be faster just to hang around until the other thread unlocks the thing. If you go to sleep on a mutex, you're basically assured some significant dead time before you will get rescheduled.

In short for the best case, a spin lock on a uniprocessor system will waste resources, slowing down the owner of the lock; in the worst case, it will deadlock the processor.

answer Dec 2, 2014 by Salil Agrawal
Similar Questions
+2 votes

Can I assign one structure variable of another structure variable of same structure type all the time ?

+2 votes

Here my doubt is about acquire mutex lock.

Here pthread_mutex_t lock ; is also a global variable shared to threads. Accessing of this global variable (lock) will it be shame as accessing of other global variables ? If same, then don't we face same problem what we will face for other global variables ? if not ,how this is discriminated from other global variables ?

+2 votes

write functions to read and write in a hash table in a multi threaded environment. Approach should give decent optimization in terms of time complexity.

...