What is the $thread- > done of php multithreaded pthread?

the pause code is as follows:

$this->synchronized(function($thread){
    if (!$thread->done)
        $thread->wait();
}, $this);

the wake-up code is as follows:

$my->synchronized(function($thread){
    $thread->done = true;
    $thread->notify();
}, $my);

then. What on earth is that thread- > done? Why does it still work when I get rid of the program?
Please all bosses to give us some advice.

Mar.15,2021

here done is a common field, which is actually the same as the following, which is the basic usage of PHP:

class A {
}

$a = new A();
$a->done = true;

Run

your complete code should be an example in pthread:

<?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());

start () starts running run () in the child thread, which is done has not yet been assigned, so wait () will be executed. The main thread then executes notofy () to wake up the child threads that are wait () .

another case is that the main thread first assigns and executes notify () to done , and then executes run () to the child thread. At this time, the child thread does not need wait , because the main thread is already notify () .

Menu