diff options
| author | ruki <[email protected]> | 2025-11-07 00:57:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-07 15:01:57 +0800 |
| commit | cf31cdc6eacf6a793989df538ecc7a00d48c6457 (patch) | |
| tree | 2b412a198278e56db02a36ebc2856bfc0282eedf /xmake/core/base/thread.lua | |
| parent | 7a9f4ecfcb3c493ebd54f3d5686e8da2bdbe9862 (diff) | |
fix thread wait
Diffstat (limited to 'xmake/core/base/thread.lua')
| -rw-r--r-- | xmake/core/base/thread.lua | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/xmake/core/base/thread.lua b/xmake/core/base/thread.lua index 1586882dd..66e6ba2af 100644 --- a/xmake/core/base/thread.lua +++ b/xmake/core/base/thread.lua @@ -113,15 +113,18 @@ function _thread:start() end -- init callback info + local is_internal = self._INTERNAL local callback = string._dump(self._CALLBACK) - local callinfo = {name = self:name(), argv = argv, internal = self._INTERNAL} + local callinfo = {name = self:name(), argv = argv, internal = is_internal} -- we need a pipe pair to wait and listen thread exit event - local rpipe, wpipe = pipe.openpair("AA") - self._RPIPE = rpipe - callinfo.wpipe = libc.dataptr(wpipe:cdata(), {ffi = false}) - -- we need to suppress gc to free it, because it has been transfer to thread in another lua state instance - wpipe._PIPE = nil + if not is_internal then + local rpipe, wpipe = pipe.openpair("AA") + self._RPIPE = rpipe + callinfo.wpipe = libc.dataptr(wpipe:cdata(), {ffi = false}) + -- we need to suppress gc to free it, because it has been transfer to thread in another lua state instance + wpipe._PIPE = nil + end -- serialize and pass callback and arguments to this thread -- we do not use string.serialize to serialize callback, because it's slower (deserialize) @@ -182,7 +185,7 @@ function _thread:wait(timeout) local ok, errors local rpipe = self._RPIPE - if rpipe then + if rpipe and scheduler:co_running() then local buff = bytes(16) local read, data_or_errors = rpipe:read(buff, 1, {block = true, timeout = timeout}) if read > 0 then @@ -192,7 +195,7 @@ function _thread:wait(timeout) errors = data_or_errors end end - if not scheduler:co_running() then + if not rpipe then local waitok, wait_errors = thread.thread_wait(self:cdata(), timeout) if ok == nil or ok > 0 then ok = waitok @@ -857,7 +860,9 @@ function thread._run_thread(callback_str, callinfo_str) argv = callinfo.argv threadname = callinfo.name is_internal = callinfo.internal - wpipe = pipe.new(libc.ptraddr(callinfo.wpipe, {ffi = false})) + if callinfo.wpipe then + wpipe = pipe.new(libc.ptraddr(callinfo.wpipe, {ffi = false})) + end end end |
