PHP 8.5.0 Alpha 2 available for testing

Threaded::wait

(PECL pthreads >= 2.0.0)

Threaded::waitSincronización

Descripción

public Threaded::wait(int $timeout = ?): bool

Hace esperar al contexto llamante una notificación desde el objeto referenciado.

Parámetros

timeout

Un tiempo de espera máximo opcional, en microsegundos.

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Ejemplos

Ejemplo #1 Notificaciones y espera

<?php
class My extends Thread {
public function
run() {
/** Hace esperar este hilo **/
$this->synchronized(function($thread){
if (!
$thread->done)
$thread->wait();
},
$this);
}
}
$my = new My();
$my->start();
/** Envía la notificación al hilo que espera **/
$my->synchronized(function($thread){
$thread->done = true;
$thread->notify();
},
$my);
var_dump($my->join());
?>

El ejemplo anterior mostrará :

bool(true)

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top