Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::interprocess::named_semaphore Class Reference

A semaphore with a global name, so it can be found from different processes. More...

#include <named_semaphore.hpp>

Public Member Functions

 named_semaphore (create_only_t, const char *name, unsigned int initialCount, const permissions &perm=permissions())
 Creates a global semaphore with a name, and an initial count. More...
 
 named_semaphore (open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm=permissions())
 Opens or creates a global semaphore with a name, and an initial count. More...
 
 named_semaphore (open_only_t, const char *name)
 Opens a global semaphore with a name if that semaphore is previously. More...
 
 ~named_semaphore ()
 Destroys *this and indicates that the calling process is finished using the resource. More...
 
void post ()
 Increments the semaphore count. More...
 
void wait ()
 Decrements the semaphore. More...
 
bool try_wait ()
 Decrements the semaphore if the semaphore's value is greater than zero and returns true. More...
 
bool timed_wait (const boost::posix_time::ptime &abs_time)
 Decrements the semaphore if the semaphore's value is greater than zero and returns true. More...
 

Static Public Member Functions

static bool remove (const char *name)
 Erases a named semaphore from the system. More...
 

Friends

class ipcdetail::interprocess_tester
 

Detailed Description

A semaphore with a global name, so it can be found from different processes.

Allows several resource sharing patterns and efficient acknowledgment mechanisms.

Constructor & Destructor Documentation

boost::interprocess::named_semaphore::named_semaphore ( create_only_t  ,
const char *  name,
unsigned int  initialCount,
const permissions perm = permissions() 
)
inline

Creates a global semaphore with a name, and an initial count.

If the semaphore can't be created throws interprocess_exception

boost::interprocess::named_semaphore::named_semaphore ( open_or_create_t  ,
const char *  name,
unsigned int  initialCount,
const permissions perm = permissions() 
)
inline

Opens or creates a global semaphore with a name, and an initial count.

If the semaphore is created, this call is equivalent to named_semaphore(create_only_t, ...) If the semaphore is already created, this call is equivalent to named_semaphore(open_only_t, ... ) and initialCount is ignored.

boost::interprocess::named_semaphore::named_semaphore ( open_only_t  ,
const char *  name 
)
inline

Opens a global semaphore with a name if that semaphore is previously.

created. If it is not previously created this function throws interprocess_exception.

boost::interprocess::named_semaphore::~named_semaphore ( )
inline

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().

Member Function Documentation

void boost::interprocess::named_semaphore::post ( )
inline

Increments the semaphore count.

If there are processes/threads blocked waiting for the semaphore, then one of these processes will return successfully from its wait function. If there is an error an interprocess_exception exception is thrown.

References boost::interprocess::ipcdetail::shm_named_semaphore::post().

bool boost::interprocess::named_semaphore::remove ( const char *  name)
inlinestatic

Erases a named semaphore from the system.

Returns false on error. Never throws.

References boost::interprocess::ipcdetail::shm_named_semaphore::remove().

bool boost::interprocess::named_semaphore::timed_wait ( const boost::posix_time::ptime abs_time)
inline

Decrements the semaphore if the semaphore's value is greater than zero and returns true.

Otherwise, waits for the semaphore to the posted or the timeout expires. If the timeout expires, the function returns false. If the semaphore is posted the function returns true. If there is an error throws sem_exception

References boost::interprocess::ipcdetail::shm_named_semaphore::timed_wait().

bool boost::interprocess::named_semaphore::try_wait ( )
inline

Decrements the semaphore if the semaphore's value is greater than zero and returns true.

If the value is not greater than zero returns false. If there is an error an interprocess_exception exception is thrown.

References boost::interprocess::ipcdetail::shm_named_semaphore::try_wait().

void boost::interprocess::named_semaphore::wait ( )
inline

Decrements the semaphore.

If the semaphore value is not greater than zero, then the calling process/thread blocks until it can decrement the counter. If there is an error an interprocess_exception exception is thrown.

References boost::interprocess::ipcdetail::shm_named_semaphore::wait().

Friends And Related Function Documentation

friend class ipcdetail::interprocess_tester
friend

The documentation for this class was generated from the following file: