## NAME

ACE_Process_Semaphore - Wrapper for Dijkstra style general semaphores that work across processes.

## SYNOPSIS

    #include <ace/Synch.h>

    class ACE_Process_Semaphore
    {
      public:
        ACE_Process_Semaphore (
            u_int count = 1,
            LPCTSTR name = 0,
            void * = 0,
            int max = 0x7FFFFFFF
            );
        ~ACE_Process_Semaphore (void);
        int remove (void);
        int acquire (void);
        int tryacquire (void);
        int release (void);
        int acquire_read (void);
        int acquire_write (void);
        int tryacquire_read (void);
        int tryacquire_write (void);
        const ACE_sema_t &lock (void) const;
        void dump (void) const;
        ACE_ALLOC_HOOK_DECLARE;
      protected:
        ACE_Semaphore lock_;
        ACE_SV_Semaphore_Complex lock_;
    };

## DESCRIPTION

Wrappers for various synchronization routines.

## PUBLIC MEMBERS

    ACE_Process_Semaphore (
        u_int count = 1,
        LPCTSTR name = 0,
        void * = 0,
        int max = 0x7FFFFFFF
        );

Initialize the semaphore, with an initial value of `count` and a maximum value of `max`.

    ~ACE_Process_Semaphore (void);

Implicitly destroy the semaphore.

    int remove (void);

Explicitly destroy the semaphore.

    int acquire (void);

Block the thread until the semaphore count becomes greater than 0, then decrement it.

    int tryacquire (void);

Conditionally decrement the semaphore if count is greater than 0 (i.e., won't block). Returns -1 on failure. If we "failed" because someone else already had the lock, `errno` is set to `EBUSY`.

    int release (void);

Increment the semaphore, potentially unblocking a waiting thread.

    int acquire_read (void);

Acquire semaphore ownership. This calls `acquire` and is only here to make the `ACE_Process_Semaphore` interface consistent with the other synchronization APIs.

    int acquire_write (void);

Acquire semaphore ownership. This calls `acquire` and is only here to make the `ACE_Process_Semaphore` interface consistent with the other synchronization APIs.

    int tryacquire_read (void);

Conditionally acquire semaphore (i.e., won't block). This calls `tryacquire` and is only here to make the `ACE_Process_Semaphore` interface consistent with the other synchronization APIs. Returns -1 on failure. If we "failed" because someone else already had the lock, `errno` is set to `EBUSY`.

    int tryacquire_write (void);

Conditionally acquire semaphore (i.e., won't block). This calls `tryacquire` and is only here to make the `ACE_Process_Semaphore` interface consistent with the other synchronization APIs. Returns -1 on failure. If we "failed" because someone else already had the lock, `errno` is set to `EBUSY`.

    const ACE_sema_t &lock (void) const;

Return the underlying lock.

    void dump (void) const;

Dump the state of an object.

    ACE_ALLOC_HOOK_DECLARE;

Declare the dynamic allocation hooks.

## PROTECTED MEMBERS

    ACE_Semaphore lock_;

    ACE_SV_Semaphore_Complex lock_;

We need this to get the right semantics...

## AUTHOR

Doug Schmidt

## LIBRARY

ace