Skip to content
  • Simon Marlow's avatar
    Use a separate mutex to protect all_tasks, avoiding a lock-order-reversal · ed301949
    Simon Marlow authored
    In GHC 6.12.x I found a rare deadlock caused by this
    lock-order-reversal:
    
    AQ cap->lock
      startWorkerTask
        newTask
          AQ sched_mutex
    
    scheduleCheckBlackHoles
      AQ sched_mutex
       unblockOne_
        wakeupThreadOnCapabilty
          AQ cap->lock
    
    so sched_mutex and cap->lock are taken in a different order in two
    places.
    
    This doesn't happen in the HEAD because we don't have
    scheduleCheckBlackHoles, but I thought it would be prudent to make
    this less likely to happen in the future by using a different mutex in
    newTask.  We can clearly see that the all_tasks mutex cannot be
    involved in a deadlock, becasue we never call anything else while
    holding it.
    ed301949