---
name: "ACE_Process_Semaphore"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_Process_Semaphore"
---

# ACE\_Process\_Semaphore(3)

Wrapper for Dijkstra style general semaphores that work across processes.

## 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);
```

This method is a no-op, i.e., it doesn't remove the semaphore. If you want to remove the semaphore, you must call the remove method explicitly.

```
int remove (void);
```

Explicitly destroy the semaphore.  Note that only one thread should call this method since it doesn't protect against race conditions.

```
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
