Pergunta de entrevista da empresa Qualcomm

Difference between spinlock and mutex.

Resposta da entrevista

Sigiloso

15 de abr. de 2020

Mutex and Spinlock both uses the exclusive protocols. Let elaborate this: Mutex: 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. Applications: ->It applicable when the modifying of data is variable of time. ->When critical code contains possible blocking calls. Spinlock: 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. Application: ->This locking is held for fixed time data access of thread.