I am hacking on Cilk to add IVars to the language and as I was looking through the source code, I was wondering why in cilk-abi.c in the runtime folder there is an atomic op on the clearing of the detached flag of the returning stack frame that is called in __cilkrts_leave_frame(). Is there any contention for this flag?
Unless I am mistaken, this flag only gets set when the frame is being made runnable/unrunnable or when it is stolen. Since __cilkrts_undo_detach() is only called upon exiting the frame, and it is the current stack frame of the currently running worker, it cannot be stolen because it does not exist as part of the THE dequeue. Is that correct? The code I am referring to is as follows:
#if defined __i386__ || defined __x86_64__
__cilkrts_fence(); /* membar #StoreLoad */
sf->flags &= ~CILK_FRAME_DETACHED;
Additionally, I am curious as to what it means for a frame to win the "undo-detach race with flags" in the __cilkrts_bug print message right before __cilkrts_leave_frame() returns.
/* This path is taken when undo-detach wins the race with stealing.
Otherwise this strand terminates and the caller will be resumed
via setjmp at sync. */
if (__builtin_expect(sf->flags & CILK_FRAME_FLAGS_MASK, 0))
__cilkrts_bug("W%u: frame won undo-detach race with flags %02x\n",
From that comment, I think that my reasoning above must be wrong. Could someone help me understand how the currently active frame stack frame is/is not involved in a steal?