Skip to content

Commit 2129b1b

Browse files
committed
remove thread::exec()
1 parent aea7b3c commit 2129b1b

24 files changed

+24
-25
lines changed

examples/thread/aio.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$threads = [];
1313
$atomic = new Swoole\Thread\Atomic();
1414
for ($i = 0; $i < $c; $i++) {
15-
$threads[] = Thread::exec(__FILE__, $i, $atomic);
15+
$threads[] = new Thread(__FILE__, $i, $atomic);
1616
}
1717
for ($i = 0; $i < $c; $i++) {
1818
$threads[$i]->join();

examples/thread/argv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
var_dump($GLOBALS['argv']);
99
$n = 2;
1010
while ($n--) {
11-
$thread = Thread::exec(__FILE__, 'thread-' . $n, $argc, $argv);
11+
$thread = new Thread(__FILE__, 'thread-' . $n, $argc, $argv);
1212
$thread->join();
1313
}
1414
} else {

examples/thread/atomic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$a1 = new Atomic;
1414
$a2 = new Long;
1515
for ($i = 0; $i < $c; $i++) {
16-
$threads[] = Thread::exec(__FILE__, $i, $a1, $a2);
16+
$threads[] = new Thread(__FILE__, $i, $a1, $a2);
1717
}
1818
for ($i = 0; $i < $c; $i++) {
1919
$threads[$i]->join();

examples/thread/co.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
$list[1] = uniqid();
99
var_dump(count($list));
1010

11-
$t1 = Swoole\Thread::exec('mt.php', 'thread-1', PHP_OS, $map, $list);
12-
$t2 = Swoole\Thread::exec('mt.php', 'thread-2', PHP_OS, $map, $list);
11+
$t1 = new Swoole\Thread('mt.php', 'thread-1', PHP_OS, $map, $list);
12+
$t2 = new Swoole\Thread('mt.php', 'thread-2', PHP_OS, $map, $list);
1313

1414
//var_dump($t1->id);
1515
//var_dump($t2->id);

examples/thread/lock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
if (empty($args)) {
99
$lock = new Lock;
1010
$lock->lock();
11-
$thread = Thread::exec(__FILE__, $lock);
11+
$thread = new Thread(__FILE__, $lock);
1212
$lock->lock();
1313
echo "main thread\n";
1414
$thread->join();

examples/thread/mt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
var_dump(count($list));
2020

2121
//if ($args[0] == 'thread-2') {
22-
// $t3 = Swoole\Thread::exec('mt.php', 'thread-3', PHP_OS);
22+
// $t3 = new Swoole\Thread('mt.php', 'thread-3', PHP_OS);
2323
// $t3->join();
2424
//}
2525

examples/thread/pipe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
if (empty($args)) {
88
Co\run(function () {
99
$sockets = swoole_coroutine_socketpair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
10-
$thread = Thread::exec(__FILE__, $sockets);
10+
$thread = new Thread(__FILE__, $sockets);
1111
echo $sockets[0]->recv(8192), PHP_EOL;
1212
$thread->join();
1313
});

examples/thread/run_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
$threads = [];
88

99
for ($i = 0; $i < $c; $i++) {
10-
$threads[] = Swoole\Thread::exec('benchmark.php', 'thread-' . ($i + 1), $map);
10+
$threads[] = new Swoole\Thread('benchmark.php', 'thread-' . ($i + 1), $map);
1111
}
1212

1313
for ($i = 0; $i < $c; $i++) {

examples/thread/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$threads = [];
1212
$queue = new Queue;
1313
for ($i = 0; $i < $c; $i++) {
14-
$threads[] = Thread::exec(__FILE__, $i, $queue);
14+
$threads[] = new Thread(__FILE__, $i, $queue);
1515
}
1616
for ($i = 0; $i < $c; $i++) {
1717
$threads[$i]->join();

examples/thread/signal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Co\run(function () {
1010
echo "main thread\n";
1111
$sockets = swoole_coroutine_socketpair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
12-
$thread = Thread::exec(__FILE__, $sockets);
12+
$thread = new Thread(__FILE__, $sockets);
1313
$parent_pipe = $sockets[1];
1414
// 收到信号之后向子线程发送指令让子线程退出
1515
if (System::waitSignal(SIGTERM)) {

examples/thread/thread_pool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$threads = [];
1212
$queue = new Queue;
1313
for ($i = 0; $i < $c; $i++) {
14-
$threads[] = Thread::exec(__FILE__, $i, $queue);
14+
$threads[] = new Thread(__FILE__, $i, $queue);
1515
}
1616
while ($n--) {
1717
$queue->push(base64_encode(random_bytes(16)), Queue::NOTIFY_ONE);

ext-src/stubs/php_swoole_thread.stub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public function join(): bool {}
88
public function joinable(): bool {}
99
public function detach(): bool {}
1010

11-
public static function exec(string $script_file, mixed ...$args): Thread {}
1211
public static function getArguments(): array {}
1312
public static function getId(): int {}
1413
public static function getTsrmInfo(): array {}

tests/swoole_thread/async-io.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (empty($args)) {
2424
$atomic = new Swoole\Thread\Atomic();
2525
$atomicLong = new Swoole\Thread\Atomic\Long();
2626
for ($i = 0; $i < C; $i++) {
27-
$threads[] = Thread::exec(__FILE__, $i, $atomic, $atomicLong);
27+
$threads[] = new Thread(__FILE__, $i, $atomic, $atomicLong);
2828
}
2929
for ($i = 0; $i < C; $i++) {
3030
$threads[$i]->join();

tests/swoole_thread/atomic_ctor.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $tm->parentFunc = function () {
2222
$num2 = random_int(1 << 31, PHP_INT_MAX);
2323
$atomic1 = new Swoole\Thread\Atomic($num1);
2424
$atomic2 = new Swoole\Thread\Atomic\Long($num2);
25-
$thread = Thread::exec(__FILE__, $lock, $atomic1, $atomic2, $num1, $num2);
25+
$thread = new Thread(__FILE__, $lock, $atomic1, $atomic2, $num1, $num2);
2626
$lock->lock();
2727
echo "main thread\n";
2828
$thread->join();

tests/swoole_thread/fatal_error_1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $pm = ProcessManager::exec(function () {
1515
$args = Thread::getArguments();
1616
if (empty($args)) {
1717
echo "start child thread\n";
18-
$threads[] = Thread::exec(__FILE__, 'error');
18+
$threads[] = new Thread(__FILE__, 'error');
1919
$threads[0]->join();
2020
echo "stop thread exited\n";
2121
} else {

tests/swoole_thread/fatal_error_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $pm = ProcessManager::exec(function () {
1414
$args = Thread::getArguments();
1515
if (empty($args)) {
1616
echo "start child thread\n";
17-
$threads[] = Thread::exec(__FILE__, 'error');
17+
$threads[] = new Thread(__FILE__, 'error');
1818
$threads[0]->join();
1919
echo "stop thread exited\n";
2020
} else {

tests/swoole_thread/info.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Swoole\Thread;
1414
$tm = new \SwooleTest\ThreadManager();
1515

1616
$tm->parentFunc = function () {
17-
$thread = Thread::exec(__FILE__, 'child');
17+
$thread = new Thread(__FILE__, 'child');
1818
$info = Thread::getTsrmInfo();
1919
Assert::true($info['is_main_thread']);
2020
Assert::eq($info['api_name'], 'POSIX Threads');

tests/swoole_thread/lock.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $tm = new \SwooleTest\ThreadManager();
1717
$tm->parentFunc = function () {
1818
$lock = new Lock;
1919
$lock->lock();
20-
$thread = Thread::exec(__FILE__, $lock);
20+
$thread = new Thread(__FILE__, $lock);
2121
$lock->lock();
2222
echo "main thread\n";
2323
$thread->join();

tests/swoole_thread/pipe.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (empty($args)) {
1717
$rdata = random_bytes(random_int(1024, 2048));
1818
Co\run(function () use ($rdata) {
1919
$sockets = swoole_coroutine_socketpair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
20-
$thread = Thread::exec(__FILE__, $sockets[1], $rdata);
20+
$thread = new Thread(__FILE__, $sockets[1], $rdata);
2121
Assert::eq($sockets[0]->recv(8192), $rdata);
2222
$thread->join();
2323
echo "DONE\n";

tests/swoole_thread/queue.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (empty($args)) {
2424
$queue = new Queue;
2525
$map = new Thread\Map();
2626
for ($i = 0; $i < C; $i++) {
27-
$threads[] = Thread::exec(__FILE__, $i, $queue, $map);
27+
$threads[] = new Thread(__FILE__, $i, $queue, $map);
2828
}
2929
$n = N;
3030
while ($n--) {

tests/swoole_thread/server/base.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $tm->initFreePorts(increment: crc32(__FILE__) % 1000);
2020
$tm->parentFunc = function () use ($tm) {
2121
$queue = new Swoole\Thread\Queue();
2222
$atomic = new Swoole\Thread\Atomic(1);
23-
$thread = Thread::exec(__FILE__, $queue, $atomic);
23+
$thread = new Thread(__FILE__, $queue, $atomic);
2424
echo $queue->pop(-1);
2525
Co\run(function () use ($tm) {
2626
$cli = new Co\Client(SWOOLE_SOCK_TCP);

tests/swoole_thread/server/send_large_packet.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $tm->initFreePorts(increment: crc32(__FILE__) % 1000);
2020
$tm->parentFunc = function () use ($tm) {
2121
$queue = new Swoole\Thread\Queue();
2222
$atomic = new Swoole\Thread\Atomic(1);
23-
$thread = Thread::exec(__FILE__, $queue, $atomic);
23+
$thread = new Thread(__FILE__, $queue, $atomic);
2424
echo $queue->pop(-1);
2525

2626
$c = MAX_CONCURRENCY_LOW;

tests/swoole_thread/signal.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $args = Thread::getArguments();
1919
if (empty($args)) {
2020
Co\run(function () {
2121
$sockets = swoole_coroutine_socketpair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
22-
$thread = Thread::exec(__FILE__, $sockets[0]);
22+
$thread = new Thread(__FILE__, $sockets[0]);
2323
$parent_pipe = $sockets[1];
2424
Timer::after(500, function () {
2525
echo "timer\n";

tests/swoole_thread/stdio.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $tm = new \SwooleTest\ThreadManager();
1717
$tm->parentFunc = function () {
1818
$lock = new Lock;
1919
$lock->lock();
20-
$thread = Thread::exec(__FILE__, $lock);
20+
$thread = new Thread(__FILE__, $lock);
2121
$lock->lock();
2222
$thread->join();
2323
echo "main thread\n";

0 commit comments

Comments
 (0)