       // de-allocate any existing global memory slots.
       if (!SlotP->Prev) {
         __kmpc_data_sharing_slot *Tail = DataSharingState.TailPtr[WID];
-
-        while(Tail && Tail->Prev) {
+        while(Tail->Prev) {
           Tail = Tail->Prev;
           free(Tail->Next);
-          Tail->Next=0;
         }
-      }
-    } else {
-      // This is not the last frame popped from this slot.
-      // Reset StackP
-      StackP = FrameStart;
+        Tail->Next=0;
+      }
     }
-
-    return;
-  }
-
-  // TODO: add memory fence here when this function can be called by
-  // worker threads also. For now, this function is only called by the
-  // master thread of each team.
-
-  // TODO: implement sharing across workers.
+  }
+
+  __threadfence_block();
 }
 
 // Begin a data sharing context. Maintain a list of references to shared

// reclaim all outstanding global memory slots since it is
// likely we have reached the end of the kernel.
EXTERN void __kmpc_data_sharing_pop_stack(void *FrameStart) {
  if (IsMasterThread()) {
    unsigned WID = getWarpId();

    __kmpc_data_sharing_slot *&SlotP = DataSharingState.SlotPtr[WID];
    void *&StackP = DataSharingState.StackPtr[WID];

    // If we try to pop the last frame of the current slot we need to
    // move to the previous slot if there is one.

      // The current slot becomes the new slot.
      SlotP = NewSlot;
      // The stack pointer always points to the next free stack frame.
      StackP = &NewSlot->Data[PushSize];
      // The frame pointer always points to the beginning of the frame.
      FrameP = &NewSlot->Data[0];
    } else {
