▲ | gpderetta 4 hours ago | |||||||
All operations on a single memory location are always totally ordered in a CC system, no matter how relaxed the memory model is. Also am I understanding it correctly that n is the number of threads in your example? Don't you find it suspicious that the number of operations goes up as the thread count goes up? edit: ok, you are saying that under heavy contention the check avoids having to do the store at all. This is racy, and whether this is correct or not, would be very application specific. edit2: I thought about this a bit, and I'm not sure i can come up with a scenario where the race matters... edit3: ... as long as all threads are only doing atomic_max operations on the memory location, which an implementation can't assume. | ||||||||
▲ | Dylan16807 2 hours ago | parent [-] | |||||||
> as long as all threads are only doing atomic_max operations on the memory location, which an implementation can't assume. What assumes that? If your early read gives you a higher number, quitting out immediately is the same as doing the max that same nanosecond. You avoid setting a variable to the same value it already is. Doing or not doing that write shouldn't affect other atomics users, should it? In general, I should be able to add or remove as many atomic(x=x) operations as I want without changing the result, right? And if your early read is lower then you just do the max and having an extra read is harmless. The only case I can think of that goes wrong is the read (and elided max) happening too early in relation to accesses to other variables, but we're assuming relaxed memory order here so that's explicitly acceptable. | ||||||||
|