2
$\begingroup$

From wikipedia on lock convoy:

A lock convoy occurs when multiple threads of equal priority contend repeatedly for the same lock. Unlike deadlock and livelock situations, the threads in a lock convoy do progress; however, each time a thread attempts to acquire the lock and fails, it relinquishes the remainder of its scheduling quantum and forces a context switch. The overhead of repeated context switches and underutilization of scheduling quanta degrade overall performance.

From wikipedia on lock/thread contention contention:

lock contention: this occurs whenever one process or thread attempts to acquire a lock held by another process or thread. The more fine-grained the available locks, the less likely one process/thread will request a lock held by the other. (For example, locking a row rather than the entire table, or locking a cell rather than the entire row.);

Could somebody please elaborate a bit further on both of those things? To me it seems like they are essentially the same, or if they are not, then surely lock contention causes a lock convoy. Is that the case or are they separate and independent concepts? Also, I don't understand the sentence "it relinquishes the remainder of its scheduling quantum and forces a context switch".

$\endgroup$
1
$\begingroup$

There are two blocking approaches used in locking algorithms when a lock is busy. spin wait or block (go to sleep, relinquish processor and wait for OS to awake the thread and re-schedule). Lock convoy as mentioned will happen when blocking strategy is used.
OS schedule threads on a core in time-sliced manner. Every thread get the processor for some per-determined time-slice, say 2 ms. OS in a round-robin fashion schedule all the threads in the ready-queue one by one. If say a thread after it get schedule and start its execution, say after 100 us, ask for a lock. If the lock is busy, the thread unable to get the lock, blocks and relinquishes processor. So remaining 1.9ms (2ms-100us) time slice is not used by the thread. Even after it is awaken by the OS when lock is free, the thread has to wait for its turn in the round-robin queue. The number of active threads could be in 100's.

Lock contention causes convoy effect.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.