1
votes

From wikipedia:

Race conditions arise in software when separate computer processes or threads of execution depend on some shared state.

If I'm understanding this correctly, does this mean that the following is also a race condition eventhough shared resources are protected?

int x; // global
Thread1:

Lock(m);
x=1;
Unlock(m)

Thread2:

Lock(m);
x=2;
Unlock(m);

Clearly the output depends on the order of execution.

1
Usually you only call something a race when it is problematic. This depends on the application and the behavior you require. - Erik

1 Answers

0
votes

Your understanding is correct. This is a race condition, but it is not a data race. The difference is subtle; I tried to explain it here.