| Home | Libraries | People | FAQ | More

## Class named_mutex

boost::interprocess::named_mutex

## Synopsis

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

    class named_mutex {
    public:
      // types
      typedef unspecified construct_func_t;

      // construct/copy/destruct
      named_mutex();
      named_mutex(const named_mutex &);
      named_mutex(create_only_t, const char *,
                  const permissions & = permissions());
      named_mutex(open_or_create_t, const char *,
                  const permissions & = permissions());
      named_mutex(open_only_t, const char *);
      named_mutex& operator=(const named_mutex &);
      ~named_mutex();

      // friend functions
      friend class detail::interprocess_tester();

      // public member functions
      void unlock();
      void lock();
      bool try_lock();
      bool timed_lock(const boost::posix_time::ptime &);
      void dont_close_on_destruction();
      interprocess_mutex * mutex() const;

      // public static functions
      static bool remove(const char *);
      unspecified m_shmem;
    };

## Description

A mutex with a global name, so it can be found from different processes. This mutex can't be placed in shared memory, and each process should have it's own named_mutex.

### `named_mutex` public construct/copy/destruct

1.     named_mutex();

   @

2.     named_mutex(const named_mutex &);

3.     named_mutex(create_only_t create_only, const char * name,
                   const permissions & perm = permissions());

   Creates a global interprocess_mutex with a name. Throws interprocess_exception on error.

4.     named_mutex(open_or_create_t open_or_create, const char * name,
                   const permissions & perm = permissions());

   Opens or creates a global mutex with a name. If the mutex is created, this call is equivalent to named_mutex(create_only_t, ... ) If the mutex is already created, this call is equivalent named_mutex(open_only_t, ... ) Does not throw

5.     named_mutex(open_only_t open_only, const char * name);

   Opens a global mutex with a name if that mutex is previously created. If it is not previously created this function throws interprocess_exception.

6.     named_mutex& operator=(const named_mutex &);

7.     ~named_mutex();

   Destroys *this and indicates that the calling process is finished using the resource. The destructor function will deallocate any system resources allocated by the system for use by this process for this resource. The resource can still be opened again calling the open constructor overload. To erase the resource from the system use remove().

### `named_mutex` friend functions

1.     friend class detail::interprocess_tester();

   @ private:

### `named_mutex` public member functions

1.     void unlock();

   Unlocks a previously locked interprocess_mutex.

2.     void lock();

   Locks interprocess_mutex, sleeps when interprocess_mutex is already locked. Throws interprocess_exception if a severe error is found

3.     bool try_lock();

   Tries to lock the interprocess_mutex, returns false when interprocess_mutex is already locked, returns true when success. Throws interprocess_exception if a severe error is found

4.     bool timed_lock(const boost::posix_time::ptime & abs_time);

   Tries to lock the interprocess_mutex until time abs_time, Returns false when timeout expires, returns true when locks. Throws interprocess_exception if a severe error is found

5.     void dont_close_on_destruction();

   @

6.     interprocess_mutex * mutex() const;

### `named_mutex` public static functions

1.     static bool remove(const char * name);

   Erases a named mutex from the system. Returns false on error. Never throws.