[Gc] [PATCH] Race condition when restarting threads
hans.boehm at hp.com
Tue Jul 12 11:42:17 PDT 2005
> Your patch had the fields set as volatile, so shouldn't the
> compiler ensure that the cpu does not reorder the stores?
We had a long discussion of that on the C++ memory model list.
The answer is architecture dependent. Volatile will generally
prevent compiler reordering. It usually introduces the necessary
hardware barriers on Itanium, but not, for example, on PowerPC.
> What if you only used one field for both the stop count and
> world is stopped field (setting the flag for stopped on the
> highest bit). The value is only modified in one thread at a
> time, so you don't have to CAS or anything. The cpu would be
> forbidden from reordering writes (they shouldn't reorder
> writes to the same field).
You could probably make that work, if you can make them both fit
into a sig_atomic_t.
I adopted your version (with atomic_ops) for 7.0alpha4.
Unless we find other problems, I think the 6.6 version with the
sleep is OK as it stands. It's a bit ugly. But the sleep
code should never be executed under normal conditions. Thus
I think there's no real performance impact. And the correctness
argument is probably no more complicated than for the other options.
More information about the Gc