I _think_ your (Tom Pledger's) solution can deadlock. Suppose we have two simultaneous calls to lowerFlags (call 1) lowerFlags f1 f2 (call 2) lowerFlags f2 f1 Then we have (initially f1 and f2 are both Up) Call 1 Call 2 (sag) putMVar f1 Sagging (sag) putMVar f2 Sagging takeMVar f2 (result is Sagging) takeMVar f1 (result is Sagging) swapMVar f1 up swapMVar f2 up At this point both calls must deadlock, since you can't do a swapMVar on an empty MVar.
