guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What are the arguments in favor of delay/force in eval.c?


From: Ken Raeburn
Subject: Re: What are the arguments in favor of delay/force in eval.c?
Date: Wed, 7 Dec 2005 19:57:58 -0500

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]