Boost logo

Boost Users :

Subject: [Boost-users] boost::interprocess locks: crashes causing deadlock
From: Jonathon (thejunkjon_at_[hidden])
Date: 2010-06-24 18:51:28


Hello,

I am currently using boost::inteprocess locks for the windows
platform. I've used both the named_recursive_mutex and the
interprocess_recursive_mutex. Both implementations use the code
below:

inline void interprocess_mutex::lock(void)
{
   do{
      boost::uint32_t prev_s =
detail::atomic_cas32((boost::uint32_t*)&m_s, 1, 0);

      if (m_s == 1 && prev_s == 0){
            break;
      }
      // relinquish current timeslice
      detail::thread_yield();
   }while (true);
}

One issue that I noticed was that if a thread crashes while holding
the lock, all other threads stay blocked. If I rerun my process
again, my process just hangs at the detail::atomic_cas32() which
causes a deadlock. I've tried looking through all the other
interprocess locks, and they all seem to filter down to this call.
Can someone suggest a locking mechanism where I could lock a resource
from all other processes, but if a process crashes that currently owns
the lock, other threads will be allowed to acquire the lock? It seems
like "file lock" might do what I want, but I wasn't to sure. any
suggestions?

thx,
J


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net