-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathatomic_ctor.phpt
44 lines (38 loc) · 954 Bytes
/
atomic_ctor.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
--TEST--
swoole_thread: atomic ctor
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
skip_if_nts();
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
use Swoole\Thread;
use Swoole\Thread\Lock;
$tm = new \SwooleTest\ThreadManager();
$tm->parentFunc = function () {
$lock = new Lock;
$lock->lock();
$num1 = random_int(1, 1 << 31);
$num2 = random_int(1 << 31, PHP_INT_MAX);
$atomic1 = new Swoole\Thread\Atomic($num1);
$atomic2 = new Swoole\Thread\Atomic\Long($num2);
$thread = new Thread(__FILE__, $lock, $atomic1, $atomic2, $num1, $num2);
$lock->lock();
echo "main thread\n";
$thread->join();
};
$tm->childFunc = function ($lock, $atomic1, $atomic2, $num1, $num2) {
echo "child thread\n";
usleep(200_000);
$lock->unlock();
Assert::eq($atomic1->get(), $num1);
Assert::eq($atomic2->get(), $num2);
exit(0);
};
$tm->run();
?>
--EXPECTF--
child thread
main thread