Reputation: 25563
I am confused. As I understand, a piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads. And data race occurs when 2 instructions from different threads access the same memory location, at least one of these accesses is a write and there is no synchronization that is mandating any particular order among these accesses.
Its clear that both relate to concurrency. But are they addressing the same thing?
Upvotes: 1
Views: 378
Reputation: 66298
If a program(or its part) has a data race, then there is very high probability that the program is NOT thread safe.
Thread-safety declares ultimate property for the program, which uses multithreading. But checking this property is very difficult task and cannot be fully performed automatically (because the term correctness in multithreaded case is badly formalized).
Data race declares event, which (relatively) easy to check automatically, and having this event has high correlation with thread-unsafety.
Summarized:
Some languages prohibit to write programs with data races. For such languages:
Upvotes: 2