pht\AtomicInteger::lock
(PECL pht >= 0.0.1)
pht\AtomicInteger::lock — Acquires the atomic integer's mutex lock
Descrição
public pht\AtomicInteger::lock
(
) : void
The mutex locks of the atomic values are reentrant safe. It is therefore
valid for the same thread to reacquire a mutex lock that it has already
acquired.
Parâmetros
Esta função não possui parâmetros.
Valor Retornado
No return value.
Exemplos
Exemplo #1 Grouping together an atomic integer's operations (requiring a mutex lock)
<?php
use pht\AtomicInteger;
$atomicInteger = new AtomicInteger(2);
// assumes $atomicInteger is being used by multiple threads
$atomicInteger->lock();
$atomicInteger->set($atomicInteger->get() * 2); // double the value
$atomicInteger->unlock();
var_dump($atomicInteger->get());
O exemplo acima irá imprimir: