Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class interprocess_mutex

boost::interprocess::interprocess_mutex

Synopsis

// In header: <boost/interprocess/sync/interprocess_mutex.hpp>


class interprocess_mutex {
public:

  // public member functions
  interprocess_mutex();
  ~interprocess_mutex();
  void lock();
  bool try_lock();
  template<typename TimePoint> bool timed_lock(const TimePoint &);
  template<typename TimePoint> bool try_lock_until(const TimePoint &);
  template<typename Duration> bool try_lock_for(const Duration &);
  void unlock();
};

Description

Wraps a interprocess_mutex that can be placed in shared memory and can be shared between processes. Allows timed lock tries

interprocess_mutex public member functions

  1. interprocess_mutex();

    Constructor. Throws interprocess_exception on error.

  2. ~interprocess_mutex();

    Destructor. If any process uses the mutex after the destructor is called the result is undefined. Does not throw.

  3. void lock();

    Requires: The calling thread does not own the mutex.

    Effects: The calling thread tries to obtain ownership of the mutex, and if another thread has ownership of the mutex, it waits until it can obtain the ownership. If a thread takes ownership of the mutex the mutex must be unlocked by the same thread. Throws: interprocess_exception on error.

    Note: A program may deadlock if the thread that has ownership calls this function. If the implementation can detect the deadlock, an exception could be thrown.

  4. bool try_lock();

    Requires: The calling thread does not own the mutex.

    Effects: The calling thread tries to obtain ownership of the mutex, and if another thread has ownership of the mutex returns immediately. Returns: If the thread acquires ownership of the mutex, returns true, if the another thread has ownership of the mutex, returns false. Throws: interprocess_exception on error.

    Note: A program may deadlock if the thread that has ownership calls this function. If the implementation can detect the deadlock, an exception could be thrown.

  5. template<typename TimePoint> bool timed_lock(const TimePoint & abs_time);

    Requires: The calling thread does not own the mutex.

    Effects: The calling thread will try to obtain exclusive ownership of the mutex if it can do so in until the specified time is reached. Returns: If the thread acquires ownership of the mutex, returns true, if the timeout expires returns false. Throws: interprocess_exception on error.

    Note: A program may deadlock if the thread that has ownership calls this function. If the implementation can detect the deadlock, an exception could be thrown.

  6. template<typename TimePoint> bool try_lock_until(const TimePoint & abs_time);

    Same as timed_lock, but this function is modeled after the standard library interface.

  7. template<typename Duration> bool try_lock_for(const Duration & dur);

    Same as timed_lock, but this function is modeled after the standard library interface.

  8. void unlock();

    Effects: The calling thread releases the exclusive ownership of the mutex. Throws: interprocess_exception on error.


PrevUpHomeNext