The terms contention
and race
are used interchangeably when it comes to thread's state(at critical section). Are they same?
-
$\begingroup$ Welcome! Please do not post the same question on multiple sites. Each community should have an honest shot at answering without wasting anybody's time. If you don't get a satisfying answer after a week or so, you may flag to request migration. $\endgroup$– John L.May 21, 2020 at 19:15
-
$\begingroup$ Cross-posted: stackoverflow.com/q/61919294/781723, cs.stackexchange.com/q/126013/755, unix.stackexchange.com/q/587920/9812. $\endgroup$– D.W. ♦May 21, 2020 at 23:25
1 Answer
These are two distinct phenomena. Contention refers to the fact that when thread $A$ has accessed a resource $B$ needs to wait until $A$ frees it.
Race refers to the fact when both threads $A$ and $B$ want to secure access to a resource. The fastest will secure it and thus lead to contention.
-
$\begingroup$ +1, although it's worth mentioning that a race does not necessarily lead to observable contention. This depends on how the processes are scheduled. For example if we use a single processor we might be able to guarantee that neither thread is ever blocked by the other, e.g. if A and B race to acquire a resource but both always manage to free it within a single scheduling quantum. Of course there could be contention elsewhere (e.g. in the caching protocol) but at least A and B will never need to wait for the other to free the resource. $\endgroup$ May 21, 2020 at 15:52