Skip to content

Commit bd219ac

Browse files
committed
#25: Add fiber destructor edge case
1 parent 80e3a5a commit bd219ac

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
Fibers in destructors 006: multiple GC runs
3+
--FILE--
4+
<?php
5+
6+
register_shutdown_function(function () {
7+
printf("Shutdown\n");
8+
});
9+
10+
class Cycle {
11+
public static $counter = 0;
12+
public $self;
13+
public function __construct() {
14+
$this->self = $this;
15+
}
16+
public function __destruct() {
17+
$id = self::$counter++;
18+
printf("%d: Start destruct\n", $id);
19+
if ($id === 0) {
20+
global $f2;
21+
$f2 = Fiber::getCurrent();
22+
Fiber::suspend(new stdClass);
23+
}
24+
printf("%d: End destruct\n", $id);
25+
}
26+
}
27+
28+
$f = new Fiber(function () {
29+
new Cycle();
30+
new Cycle();
31+
gc_collect_cycles();
32+
});
33+
34+
$f->start();
35+
36+
new Cycle();
37+
new Cycle();
38+
gc_collect_cycles();
39+
40+
$f2->resume();
41+
42+
?>
43+
--EXPECT--
44+
0: Start destruct
45+
1: Start destruct
46+
1: End destruct
47+
2: Start destruct
48+
2: End destruct
49+
3: Start destruct
50+
3: End destruct
51+
0: End destruct
52+
Shutdown

0 commit comments

Comments
 (0)