forked from krakjoe/pthreads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinding.phpt
55 lines (51 loc) · 1.11 KB
/
binding.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--TEST--
Test pthreads connections
--DESCRIPTION--
This test verifies that variables are bound properly by pthreads
--FILE--
<?php
class ThreadTesting extends Thread {
public $other;
public $done;
public function setOther($other){
$this->other = $other;
}
public function run(){
$this->synchronized(function($that) {
$that->done = true;
$that->notify();
}, $this);
}
}
class ThreadTest extends Thread {
public $other;
public $done;
public function setOther($other){
$this->other = $other;
}
public function run(){
$this->synchronized(function($that) {
$that->done = true;
$that->notify();
}, $this);
}
}
$threads[0]=new ThreadTesting();
$threads[1]=new ThreadTest();
$threads[0]->setOther($threads[1]);
$threads[1]->setOther($threads[0]);
foreach($threads as $thread)
$thread->start();
foreach($threads as $thread) {
$thread->synchronized(function() use($thread){
if (!$thread->done)
var_dump($thread->wait());
else var_dump($thread->done);
});
}
foreach ($threads as $thread)
$thread->join();
?>
--EXPECT--
bool(true)
bool(true)