---
name: "ThreadLock"
section: "3cc"
platform: "linux"
package: "libcommoncpp2-dev"
version: "1.0.13-5"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/ThreadLock"
---

# ThreadLock(3cc)

The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have rwlock support, and reverts to a simple mutex for those that do not. Posix rwlock extension for protected access.

## NAME

ThreadLock - The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have rwlock support, and reverts to a simple mutex for those that do not. Posix rwlock extension for protected access.

## SYNOPSIS

`#include <thread.h>`

### Public Methods

**ThreadLock** ()\
 *Create a process shared thread lock object.* virtual **~ThreadLock** ()\
 *Destroy a process shared thread lock object.* void **readLock** (void)\
 *Aquire a read lock for the current object.* void **writeLock** (void)\
 *Aquire a write lock for the current object.* bool **tryReadLock** (void)\
 *Attempt read lock for current object.* bool **tryWriteLock** (void)\
 *Attempt write lock for current object.* void **unlock** (void)\
 *Release any held locks.*

## DETAILED DESCRIPTION

The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have rwlock support, and reverts to a simple mutex for those that do not. Posix rwlock extension for protected access.

**Author:**  David Sugar \<dyfet@ostel.com\>

## CONSTRUCTOR & DESTRUCTOR DOCUMENTATION

### ThreadLock::ThreadLock ()

Create a process shared thread lock object.

### virtual ThreadLock::~ThreadLock ()` [virtual]`

Destroy a process shared thread lock object.

## MEMBER FUNCTION DOCUMENTATION

### void ThreadLock::readLock (void)

Aquire a read lock for the current object.

### bool ThreadLock::tryReadLock (void)

Attempt read lock for current object.

**Returns:**  true on success.

### bool ThreadLock::tryWriteLock (void)

Attempt write lock for current object.

**Returns:**  true on success.

### void ThreadLock::unlock (void)

Release any held locks.

### void ThreadLock::writeLock (void)

Aquire a write lock for the current object.

## AUTHOR

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