On Dec 7, 2005, at 17:47, Rob Browning wrote:
{
SCM ans = scm_call_0(SCM_PROMISE_DATA (ans));
SCM_SET_PROMISE_DATA(p, ans);
SCM_SET_PROMISE_MUTEX(p, SCM_BOOL_F) // (do last to avoid
race at [1])
result = SCM_PROMISE_DATA(p);
}
Of course, the compiler might reorder these accesses, unless you make
everything volatile. Even then, the CPU still might reorder them so
another compiler might see something different. I'd be worried about
the reordering or caching in another processor if the code decides it
can bypass all the mutex stuff, too.
Once every thread agrees on the new data value and no mutex needed,
everything should be fine, but managing the transition to that state
(without adding *another* mutex) is very tricky.
scm_unlock_mutex(mutex);
That (and the lock call) is probably the only barrier past which you
can safely assume that non-volatile accesses won't be reordered.
(And for CPU reordering, you probably shouldn't depend too much on
simply declaring storage to be volatile. AFAIK most compilers won't
insert memory-barrier instructions before and after every volatile
access.) Actually, I think some memory models will allow some
accesses to be moved into the region where the lock is held from
outside it.
Ken
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel