Skip to content

Commit

Permalink
remove thread::exec()
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jun 11, 2024
1 parent aea7b3c commit 2129b1b
Show file tree
Hide file tree
Showing 24 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/thread/aio.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$threads = [];
$atomic = new Swoole\Thread\Atomic();
for ($i = 0; $i < $c; $i++) {
$threads[] = Thread::exec(__FILE__, $i, $atomic);
$threads[] = new Thread(__FILE__, $i, $atomic);
}
for ($i = 0; $i < $c; $i++) {
$threads[$i]->join();
Expand Down
2 changes: 1 addition & 1 deletion examples/thread/argv.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var_dump($GLOBALS['argv']);
$n = 2;
while ($n--) {
$thread = Thread::exec(__FILE__, 'thread-' . $n, $argc, $argv);
$thread = new Thread(__FILE__, 'thread-' . $n, $argc, $argv);
$thread->join();
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/thread/atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$a1 = new Atomic;
$a2 = new Long;
for ($i = 0; $i < $c; $i++) {
$threads[] = Thread::exec(__FILE__, $i, $a1, $a2);
$threads[] = new Thread(__FILE__, $i, $a1, $a2);
}
for ($i = 0; $i < $c; $i++) {
$threads[$i]->join();
Expand Down
4 changes: 2 additions & 2 deletions examples/thread/co.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
$list[1] = uniqid();
var_dump(count($list));

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

//var_dump($t1->id);
//var_dump($t2->id);
Expand Down
2 changes: 1 addition & 1 deletion examples/thread/lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if (empty($args)) {
$lock = new Lock;
$lock->lock();
$thread = Thread::exec(__FILE__, $lock);
$thread = new Thread(__FILE__, $lock);
$lock->lock();
echo "main thread\n";
$thread->join();
Expand Down
2 changes: 1 addition & 1 deletion examples/thread/mt.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
var_dump(count($list));

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

Expand Down
2 changes: 1 addition & 1 deletion examples/thread/pipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if (empty($args)) {
Co\run(function () {
$sockets = swoole_coroutine_socketpair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
$thread = Thread::exec(__FILE__, $sockets);
$thread = new Thread(__FILE__, $sockets);
echo $sockets[0]->recv(8192), PHP_EOL;
$thread->join();
});
Expand Down
2 changes: 1 addition & 1 deletion examples/thread/run_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$threads = [];

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

for ($i = 0; $i < $c; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/thread/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$threads = [];
$queue = new Queue;
for ($i = 0; $i < $c; $i++) {
$threads[] = Thread::exec(__FILE__, $i, $queue);
$threads[] = new Thread(__FILE__, $i, $queue);
}
for ($i = 0; $i < $c; $i++) {
$threads[$i]->join();
Expand Down
2 changes: 1 addition & 1 deletion examples/thread/signal.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Co\run(function () {
echo "main thread\n";
$sockets = swoole_coroutine_socketpair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
$thread = Thread::exec(__FILE__, $sockets);
$thread = new Thread(__FILE__, $sockets);
$parent_pipe = $sockets[1];
// 收到信号之后向子线程发送指令让子线程退出
if (System::waitSignal(SIGTERM)) {
Expand Down
2 changes: 1 addition & 1 deletion examples/thread/thread_pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$threads = [];
$queue = new Queue;
for ($i = 0; $i < $c; $i++) {
$threads[] = Thread::exec(__FILE__, $i, $queue);
$threads[] = new Thread(__FILE__, $i, $queue);
}
while ($n--) {
$queue->push(base64_encode(random_bytes(16)), Queue::NOTIFY_ONE);
Expand Down
1 change: 0 additions & 1 deletion ext-src/stubs/php_swoole_thread.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public function join(): bool {}
public function joinable(): bool {}
public function detach(): bool {}

public static function exec(string $script_file, mixed ...$args): Thread {}
public static function getArguments(): array {}
public static function getId(): int {}
public static function getTsrmInfo(): array {}
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/async-io.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (empty($args)) {
$atomic = new Swoole\Thread\Atomic();
$atomicLong = new Swoole\Thread\Atomic\Long();
for ($i = 0; $i < C; $i++) {
$threads[] = Thread::exec(__FILE__, $i, $atomic, $atomicLong);
$threads[] = new Thread(__FILE__, $i, $atomic, $atomicLong);
}
for ($i = 0; $i < C; $i++) {
$threads[$i]->join();
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/atomic_ctor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $tm->parentFunc = function () {
$num2 = random_int(1 << 31, PHP_INT_MAX);
$atomic1 = new Swoole\Thread\Atomic($num1);
$atomic2 = new Swoole\Thread\Atomic\Long($num2);
$thread = Thread::exec(__FILE__, $lock, $atomic1, $atomic2, $num1, $num2);
$thread = new Thread(__FILE__, $lock, $atomic1, $atomic2, $num1, $num2);
$lock->lock();
echo "main thread\n";
$thread->join();
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/fatal_error_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $pm = ProcessManager::exec(function () {
$args = Thread::getArguments();
if (empty($args)) {
echo "start child thread\n";
$threads[] = Thread::exec(__FILE__, 'error');
$threads[] = new Thread(__FILE__, 'error');
$threads[0]->join();
echo "stop thread exited\n";
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/fatal_error_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $pm = ProcessManager::exec(function () {
$args = Thread::getArguments();
if (empty($args)) {
echo "start child thread\n";
$threads[] = Thread::exec(__FILE__, 'error');
$threads[] = new Thread(__FILE__, 'error');
$threads[0]->join();
echo "stop thread exited\n";
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/info.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Swoole\Thread;
$tm = new \SwooleTest\ThreadManager();

$tm->parentFunc = function () {
$thread = Thread::exec(__FILE__, 'child');
$thread = new Thread(__FILE__, 'child');
$info = Thread::getTsrmInfo();
Assert::true($info['is_main_thread']);
Assert::eq($info['api_name'], 'POSIX Threads');
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/lock.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $tm = new \SwooleTest\ThreadManager();
$tm->parentFunc = function () {
$lock = new Lock;
$lock->lock();
$thread = Thread::exec(__FILE__, $lock);
$thread = new Thread(__FILE__, $lock);
$lock->lock();
echo "main thread\n";
$thread->join();
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/pipe.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (empty($args)) {
$rdata = random_bytes(random_int(1024, 2048));
Co\run(function () use ($rdata) {
$sockets = swoole_coroutine_socketpair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
$thread = Thread::exec(__FILE__, $sockets[1], $rdata);
$thread = new Thread(__FILE__, $sockets[1], $rdata);
Assert::eq($sockets[0]->recv(8192), $rdata);
$thread->join();
echo "DONE\n";
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/queue.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (empty($args)) {
$queue = new Queue;
$map = new Thread\Map();
for ($i = 0; $i < C; $i++) {
$threads[] = Thread::exec(__FILE__, $i, $queue, $map);
$threads[] = new Thread(__FILE__, $i, $queue, $map);
}
$n = N;
while ($n--) {
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/server/base.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $tm->initFreePorts(increment: crc32(__FILE__) % 1000);
$tm->parentFunc = function () use ($tm) {
$queue = new Swoole\Thread\Queue();
$atomic = new Swoole\Thread\Atomic(1);
$thread = Thread::exec(__FILE__, $queue, $atomic);
$thread = new Thread(__FILE__, $queue, $atomic);
echo $queue->pop(-1);
Co\run(function () use ($tm) {
$cli = new Co\Client(SWOOLE_SOCK_TCP);
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/server/send_large_packet.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $tm->initFreePorts(increment: crc32(__FILE__) % 1000);
$tm->parentFunc = function () use ($tm) {
$queue = new Swoole\Thread\Queue();
$atomic = new Swoole\Thread\Atomic(1);
$thread = Thread::exec(__FILE__, $queue, $atomic);
$thread = new Thread(__FILE__, $queue, $atomic);
echo $queue->pop(-1);

$c = MAX_CONCURRENCY_LOW;
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/signal.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $args = Thread::getArguments();
if (empty($args)) {
Co\run(function () {
$sockets = swoole_coroutine_socketpair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
$thread = Thread::exec(__FILE__, $sockets[0]);
$thread = new Thread(__FILE__, $sockets[0]);
$parent_pipe = $sockets[1];
Timer::after(500, function () {
echo "timer\n";
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/stdio.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $tm = new \SwooleTest\ThreadManager();
$tm->parentFunc = function () {
$lock = new Lock;
$lock->lock();
$thread = Thread::exec(__FILE__, $lock);
$thread = new Thread(__FILE__, $lock);
$lock->lock();
$thread->join();
echo "main thread\n";
Expand Down

0 comments on commit 2129b1b

Please sign in to comment.