---
name: "ost_SemaphoreLock"
section: "3"
platform: "linux"
package: "libcommoncpp2-doc"
version: "1.8.1-10"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/ost_SemaphoreLock"
---

# ost\_SemaphoreLock(3)

The SemaphoreLock class is used to protect a section of code through a semaphore so that only x instances of the member function may execute concurrently.

## NAME

ost::SemaphoreLock - The **SemaphoreLock** class is used to protect a section of code through a semaphore so that only x instances of the member function may execute concurrently.

## SYNOPSIS

`#include <thread.h>`

### Public Member Functions

**SemaphoreLock** (**Semaphore** &\_sem)\
 Wait for the semaphore.  **~SemaphoreLock** ()\
 Post the semaphore automatically.

## Detailed Description

The **SemaphoreLock** class is used to protect a section of code through a semaphore so that only x instances of the member function may execute concurrently.

A common use is

void func\_to\_protect() { **SemaphoreLock** lock(semaphore); ... operation ... }

NOTE: do not declare variable as 'SemaohoreLock (semaphore)', the mutex will be released at statement end.

**Author**

David Sugar dyfet@gnu.org

**Semaphore** automatic locker for protected access.

## Constructor & Destructor Documentation

### ost::SemaphoreLock::SemaphoreLock (Semaphore & \_sem)` [inline]`

Wait for the semaphore.

References ost::Semaphore::wait().

### ost::SemaphoreLock::~SemaphoreLock ()` [inline]`

Post the semaphore automatically.

References ost::Semaphore::post().

## Author

Generated automatically by Doxygen for GNU CommonC++ from the source code.
