pthreads
PHP Manual

The Volatile class

(PECL pthreads >= 3.0.0)

Введение

The Volatile class is new to pthreads v3. Its introduction is a consequence of the new immutability semantics of Threaded members of Threaded classes. The Volatile class enables for mutability of its Threaded members, and is also used to store PHP arrays in Threaded contexts.

Обзор классов

Volatile extends Threaded implements Collectable , Traversable {
/* Наследуемые методы */
public array Threaded::chunk ( integer $size , boolean $preserve )
public integer Threaded::count ( void )
public bool Threaded::extend ( string $class )
public Threaded Threaded::from ( Closure $run [, Closure $construct [, array $args ]] )
public array Threaded::getTerminationInfo ( void )
public boolean Threaded::isRunning ( void )
public boolean Threaded::isTerminated ( void )
public boolean Threaded::isWaiting ( void )
public boolean Threaded::lock ( void )
public boolean Threaded::merge ( mixed $from [, bool $overwrite ] )
public boolean Threaded::notify ( void )
public boolean Threaded::notifyOne ( void )
public boolean Threaded::pop ( void )
public void Threaded::run ( void )
public mixed Threaded::shift ( void )
public mixed Threaded::synchronized ( Closure $block [, mixed $... ] )
public boolean Threaded::unlock ( void )
public boolean Threaded::wait ([ integer $timeout ] )
}

Примеры

Пример #1 New immutability semantics of Threaded

<?php

class Task extends Threaded
{
    public function 
__construct()
    {
        
$this->data = new Threaded();

        
// attempt to overwrite a Threaded property of a Threaded class (invalid)
        
$this->data = new StdClass();
    }
}

var_dump((new Task())->data);

Результатом выполнения данного примера будет что-то подобное:

RuntimeException: Threaded members previously set to Threaded objects are immutable, cannot overwrite data in %s:%d

Пример #2 Volatile use-case

<?php

class Task extends Volatile
{
    public function 
__construct()
    {
        
$this->data = new Threaded();

        
// attempt to overwrite a Threaded property of a Volatile class (valid)
        
$this->data = new StdClass();
    }
}

var_dump((new Task())->data);

Результатом выполнения данного примера будет что-то подобное:

object(stdClass)#3 (0) {
}

pthreads
PHP Manual