0
$\begingroup$

The terms contention and race are used interchangeably when it comes to thread's state(at critical section). Are they same?

$\endgroup$
2

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
1
  • $\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

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.