system
Introduction
Process Control Extensions
PHP Manual

# pthreads

Table of Contents

- Introduction
- Installing/Configuring
  - Requirements
  - Installation
  - Runtime Configuration
  - Resource Types
- Predefined Constants
- Thread — The Thread class
  - Thread::chunk — Manipulation
  - Thread::getCreatorId — Identification
  - Thread::getCurrentThreadId — Identification
  - Thread::getThreadId — Identification
  - Thread::isJoined — State Detection
  - Thread::isRunning — State Detection
  - Thread::isStarted — State Detection
  - Thread::isTerminated — State Detection
  - Thread::isWaiting — State Detection
  - Thread::join — Synchronization
  - Thread::lock — Synchronization
  - Thread::merge — Manipulation
  - Thread::notify — Synchronization
  - Thread::pop — Manipulation
  - Thread::run — Execution
  - Thread::shift — Manipulation
  - Thread::start — Execution
  - Thread::synchronized — Synchronization
  - Thread::unlock — Synchronization
  - Thread::wait — Synchronization
- Worker — The Worker class
  - Worker::chunk — Manipulation
  - Worker::getCreatorId — Identification
  - Worker::getStacked — Stack Analysis
  - Worker::getThreadId — Identification
  - Worker::isShutdown — State Detection
  - Worker::isWorking — State Detection
  - Worker::merge — Manipulation
  - Worker::pop — Manipulation
  - Worker::run — Execution
  - Worker::shift — Manipulation
  - Worker::shutdown — Synchronization
  - Worker::stack — Stacking
  - Worker::start — Execution
  - Worker::unstack — Stacking
- Stackable — The Stackable class
  - Stackable::chunk — Manipulation
  - Stackable::isRunning — State Detection
  - Stackable::isTerminated — State Detection
  - Stackable::isWaiting — State Detection
  - Stackable::lock — Synchronization
  - Stackable::merge — Manipulation
  - Stackable::notify — Synchronization
  - Stackable::pop — Manipulation
  - Stackable::run — Execution
  - Stackable::shift — Manipulation
  - Stackable::synchronized — Synchronization
  - Stackable::unlock — Synchronization
  - Stackable::wait — Synchronization
- Modifiers — Method Modifiers
- Mutex — The Mutex class
  - Mutex::create — Create a Mutex
  - Mutex::destroy — Destroy Mutex
  - Mutex::lock — Acquire Mutex
  - Mutex::trylock — Attempt to Acquire Mutex
  - Mutex::unlock — Release Mutex
- Cond — The Cond class
  - Cond::broadcast — Broadcast a Condition
  - Cond::create — Create a Condition
  - Cond::destroy — Destroy a Condition
  - Cond::signal — Signal a Condition
  - Cond::wait — Wait for Condition

# The Thread class

## Introduction

An implementation of a Thread should extend this declaration, implementing the run method. When the start method of that object is called, the run method code will be executed in separate Thread.

## Class synopsis

Thread
class Thread {
/* Methods */
final public boolean chunk ( long `$size` , boolean `$preserve` )
final public long getCreatorId ( void )
final public static long getCurrentThreadId ( void )
final public long getThreadId ( void )
final public boolean isJoined ( void )
final public boolean isRunning ( void )
final public boolean isStarted ( void )
final public boolean isTerminated ( void )
final public boolean isWaiting ( void )
final public boolean join ( void )
final public boolean lock ( void )
final public boolean merge ( mixed `$from` [, mixed `$overwrite` ] )
final public boolean notify ( void )
final public boolean pop ( void )
abstract public void run ( void )
final public boolean shift ( void )
final public boolean start ([ long `$options` ] )
final public mixed synchronized ( Closure `$block` [, mixed `$...` ] )
final public boolean unlock ( void )
final public boolean wait ([ long `$timeout` ] )
}

# The Worker class

## Introduction

Worker Threads have a persistent context, as such should be used over Threads in most cases.

## Class synopsis

Worker
class Worker {
/* Methods */
final public boolean chunk ( long `$size` , boolean `$preserve` )
final public long getCreatorId ( void )
final public int getStacked ( void )
final public long getThreadId ( void )
final public boolean isShutdown ( void )
final public boolean isWorking ( void )
final public boolean merge ( mixed `$from` [, mixed `$overwrite` ] )
final public boolean pop ( void )
abstract public void run ( void )
final public boolean shift ( void )
final public boolean shutdown ( void )
final public int stack ( Stackable `$work` )
final public boolean start ([ long `$options` ] )
final public int unstack ([ Stackable `$work` ] )
}

# The Stackable class

## Introduction

Stackables are tasks that are executed by Worker threads. You can synchronize with, read, and write Stackable objects before, after and during their execution.

## Class synopsis

Stackable
class Stackable {
/* Methods */
final public boolean chunk ( long `$size` , boolean `$preserve` )
final public boolean isRunning ( void )
final public boolean isTerminated ( void )
final public boolean isWaiting ( void )
final public boolean lock ( void )
final public boolean merge ( mixed `$from` [, mixed `$overwrite` ] )
final public boolean notify ( void )
final public boolean pop ( void )
abstract public void run ( void )
final public boolean shift ( void )
final public mixed synchronized ( Closure `$block` [, mixed `$...` ] )
final public boolean unlock ( void )
final public boolean wait ([ string `$timeout` ] )
}

# The Mutex class

## Introduction

The static methods contained in the Mutex class provide direct access to Posix Mutex functionality.

## Class synopsis

Mutex
class Mutex {
/* Methods */
final public static long create ([ boolean `$lock` ] )
final public static boolean destroy ( long `$mutex` )
final public static boolean lock ( long `$mutex` )
final public static boolean trylock ( long `$mutex` )
final public static boolean unlock ( long `$mutex` [, boolean `$destroy` ] )
}

# The Cond class

## Introduction

The static methods contained in the Cond class provide direct access to Posix Condition Variables.

## Class synopsis

Cond
class Cond {
/* Methods */
final public static boolean broadcast ( long `$condition` )
final public static long create ( void )
final public static boolean destroy ( long `$condition` )
final public static boolean signal ( long `$condition` )
final public static boolean wait ( long `$condition` , long `$mutex` [, long `$timeout` ] )
}