Qualcomm Interview Question: Difference between spinlock a... | Glassdoor.co.in

Interview Question

Embedded Software Engineer Interview

Difference between spinlock and mutex.


Interview Answer

2 Answers


Mutex and Spinlock both uses the exclusive protocols.
Let elaborate this:
Mutex uses the Counter and Wait Queue to overcome the race instruction problem.
When more than one thread try to execute the same data, then only one thread is success to access the data from memory by decreasing the counter value to zero and hold the lock (this is known as the lock delivered by thread) and other thread is put into Wait Queue. If any other thread try to access the same data then, first it should decrease the counter value. Will decreasing if counter value is zero than that thread is also put into Wait Queue. Only thread which hold the lock can release lock by increasing the count value to one. Then other thread can access the data.
->It applicable when the modifying of data is variable of time.
->When critical code contains possible blocking calls.

Spinlock use the Counter and Loops to over the race instruction problem. When thread hold the lock on access of data and if any other thread try to access the same data, then thread which don't
hold the lock put into loop until thread which hold lock is release the lock or unlock.
->This locking is held for fixed time data access of thread.

Anonymous on 14-Apr-2020

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

Add Answers or Comments

To comment on this, Sign In or Sign Up.