Question

1.10/6:

All modifications to a particular atomic object M occur in some particular total order, called the modification order of M.

Do non-atomic objects also have same modification order in all threads? I am interested in properly synchronized cases (in absence of data races, etc).

Was it helpful?

Solution

You need to have synchronization between all participating threads.

If you have one (or more) thread(s) updating a non-atomic value (with any amount of synchronizing operations among their group) and another thread reading that value (without synchronizing with any updater threads), you are not even guaranteed that you will read one of the values the other threads have stored.

Generally, if one thread updates a non-atomic variable and another accesses (updates or reads) it without proper synchronization between these two operations, you have a data race. A data race causes undefined behavior.

If you "properly synchronize" accesses to a non-atomic variable, you will have a happens-before relationship between any modification and any access in another (or of course the same) thread. This includes the relationship between any two modifications.

That happens-before relationship is valid across all threads and induces a total order between modifications. So, yes: properly synchronized use gives you a total modification order (which even is the same for all variables synchronized using the same synchronizing operations).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top