PHP - Fonction Threaded :: synchronized ()

Threaded :: synchronized - Synchronisation

Syntaxe

public mixed Threaded::synchronized( Closure $block [, mixed $... ] )

La fonction Threaded :: synchronized () peut exécuter le bloc tout en conservant un verrou de synchronisation des objets référencés pour le contexte appelant.

La fonction Threaded :: synchronized () peut renvoyer une valeur du bloc.

Exemple

<?php
   class My extends Thread {
      public function run() {
         $this->synchronized(function($thread) {
            if(!$thread->done)
               $thread->wait();
         }, $this);
      }
   }
   $my = new My();
   $my->start();
   
   $my->synchronized(function($thread) {
      $thread->done = true;
      $thread->notify();
   }, $my);
   var_dump($my->join());
?>