-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetOrSet3.php
More file actions
61 lines (52 loc) · 1.16 KB
/
getOrSet3.php
File metadata and controls
61 lines (52 loc) · 1.16 KB
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
56
57
58
59
60
<?php
pthread_sigmask(SIG_SETMASK, []);
$running = true;
pcntl_async_signals(true);
pcntl_signal(SIGINT, function() use(&$running) {
printf("SIGINT\n");
$running = false;
}, false);
$var1 = ts_var_declare(1);
$var2 = ts_var_declare(2);
register_shutdown_function(function() {
printf("EXIT: %s\n", THREAD_TASK_NAME);
});
if(!is_main_task()) {
$i = 0;
if(THREAD_TASK_NAME == 'task0') {
while($running) {
ts_var_get_or_set($var1, ++$i, function() use($var2, &$i) {
return ts_var_get_or_set($var2, ++$i, function() use($i) {
usleep(5000); // 5ms
return $i;
});
});
if($i >= 10000) {
$i = 0;
echo "OK\n";
}
}
} else {
while($running) {
ts_var_get_or_set($var2, ++$i, function() use($var1, &$i) {
ts_var_get_or_set($var1, ++$i, function() {
usleep(5000); // 5ms
return 1;
});
});
if($i >= 10000) {
$i = 0;
echo "OK\n";
}
}
}
} else {
create_task('task0', __FILE__, [], null, null, $waits[0]);
create_task('task1', __FILE__, [], null, null, $waits[1]);
$var = ts_var_declare(null);
while($running && ($n = task_get_threads()) > 0) {
sleep(1);
echo "$n\n";
}
task_wait(SIGINT);
}