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

# thread.h(3)

Synchronization and threading services.

## NAME

thread.h - Synchronization and threading services.

## SYNOPSIS

`#include <cc++/config.h>`\
 `#include <cc++/string.h>`\
 `#include <ctime>`\
 `#include <pthread.h>`\
 `#include <time.h>`\
 `#include <signal.h>`\
 `#include <unistd.h>`\

### Classes

class **ost::Mutex**\
 The **Mutex** class is used to protect a section of code so that at any given time only a single thread can perform the protected operation.  class **ost::MutexLock**\
 The **MutexLock** class is used to protect a section of code so that at any given time only a single thread can perform the protected operation.  class **ost::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.  class **ost::ReadLock**\
 The **ReadLock** class is used to protect a section of code through a **ThreadLock** for 'read' access to the member function.  class **ost::WriteLock**\
 The **WriteLock** class is used to protect a section of code through a **ThreadLock** for 'write' access to the member function.  class **ost::MutexCounter**\
 The **Mutex** **Counter** is a counter variable which can safely be incremented or decremented by multiple threads.  class **ost::AtomicCounter**\
 The **AtomicCounter** class offers thread-safe manipulation of an integer counter.  class **ost::Conditional**\
 A conditional variable synchcronization object for one to one and one to many signal and control events between processes.  class **ost::Semaphore**\
 A semaphore is generally used as a synchronization object between multiple threads or to protect a limited and finite resource such as a memory or thread pool.  class **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.  class **ost::Event**\
 The **Event** class implements a feature originally found in the WIN32 API; event notification.  class **ost::Thread**\
 Every thread of execution in an application is created by instantiating an object of a class derived from the **Thread** class.  class **ost::Cancellation**\
 A class to automatically set the thread cancellation mode of a member function.  class **ost::PosixThread**\
 class **ost::ThreadKey**\
 This class allows the creation of a thread context unique 'pointer' that can be set and retrieved and can be used to create thread specific data areas for implementing 'thread safe' library routines.  class **ost::TimerPort**\
 Timer ports are used to provide synchronized timing events when managed under a 'service thread' such as **SocketService**.  class **ost::SysTime**\
 This class is used to access non-reentrant date and time functions in the standard C library.

### Namespaces

 **ost**\

### Macros

\#define **CCXX\_POSIX**\
 \#define **TIMEOUT\_INF**   ~((**timeout\_t**) 0)\
 \#define **ENTER\_CRITICAL**   enterMutex();\
 \#define **LEAVE\_CRITICAL**   leaveMutex();\
 \#define **ENTER\_DEFERRED**   setCancel(cancelDeferred);\
 \#define **LEAVE\_DEFERRED**   setCancel(cancelImmediate);\
 \#define **psleep**(x)   (sleep)(x)\

### Typedefs

typedef pthread\_t **cctid\_t**\
 typedef unsigned long **timeout\_t**\
 typedef int **ost::signo\_t**\

### Functions

struct timespec \* **ost::getTimeout** (struct timespec \*spec, **timeout\_t** timeout)\
 void **ost::wait** (signo\_t signo)\
 Thread \* **ost::getThread** (void)\
 struct tm \* **ost::localtime\_r** (const time\_t \*t, struct tm \*b)\
 char \* **ost::ctime\_r** (const time\_t \*t, char \*buf)\
 struct tm \* **ost::gmtime\_r** (const time\_t \*t, struct tm \*b)\
 char \* **ost::asctime\_r** (const struct tm \*tm, char \*b)\

### Variables

class **\_\_EXPORT** **ost::Thread**\
 class **\_\_EXPORT** **ost::ThreadKey**\
 class **\_\_EXPORT** **ost::Conditional**\
 class **\_\_EXPORT** **ost::Event**\

## Detailed Description

Synchronization and threading services.

## Macro Definition Documentation

### #define CCXX\_POSIX

### #define ENTER\_CRITICAL enterMutex();

### #define ENTER\_DEFERRED setCancel(cancelDeferred);

### #define LEAVE\_CRITICAL leaveMutex();

### #define LEAVE\_DEFERRED setCancel(cancelImmediate);

### #define psleep(x) (sleep)(x)

### #define TIMEOUT\_INF ~((timeout\_t) 0)

## Typedef Documentation

### typedef pthread\_t cctid\_t

### typedef unsigned long timeout\_t

## Author

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