Skip to content

Commit

Permalink
update release uv_queue thread on destruction
Browse files Browse the repository at this point in the history
- this is to improvement thread variable access the cause of `zend_mm_heap` corrupted message
  • Loading branch information
TheTechsTech committed Apr 19, 2022
1 parent 25f5f4c commit 65619d6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Spawn/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ final class Thread
/** @var boolean for **Coroutine** `yield` usage */
protected $isYield = false;
protected $isClosed = false;
protected $releaseQueue = false;

protected static $uv = null;

Expand All @@ -55,8 +56,7 @@ public function __destruct()
if (!$this->isClosed)
$this->close();

$this->result = null;
$this->exception = null;
$this->releaseQueue = true;
}

public function close()
Expand All @@ -65,8 +65,6 @@ public function close()
$this->success = null;
$this->failed = null;
$this->loop = null;
$this->threads = null;
$this->status = null;
$this->successCallbacks = [];
$this->errorCallbacks = [];
$this->isYield = false;
Expand Down Expand Up @@ -121,7 +119,7 @@ public function create($tid, callable $task, ...$args): self
$async->handlers($tid);
});

\uv_queue_work(self::$uv, function () use (&$async, &$task, $tid, &$args) {
\uv_queue_work(self::$uv, function () use (&$async, $task, $tid, &$args) {
include 'vendor/autoload.php';
try {
$result = $task(...$args);
Expand All @@ -132,7 +130,9 @@ public function create($tid, callable $task, ...$args): self

if (isset($async->threads[$tid]) && $async->threads[$tid] instanceof \UVAsync) {
\uv_async_send($async->threads[$tid]);
\usleep($async->count() * 70000);
do {
\usleep($async->count() * 70000);
} while (!$async->releaseQueue);
}
}, function () {
});
Expand Down Expand Up @@ -161,6 +161,10 @@ public function join($tid = null): void
\uv_run(self::$uv, !empty($tid) ? \UV::RUN_ONCE : \UV::RUN_NOWAIT);
}
}

if (!empty($tid)) {
$this->releaseQueue = true;
}
}

/**
Expand Down

0 comments on commit 65619d6

Please sign in to comment.