@@ -113,15 +113,18 @@ function _thread:start()
113113 end
114114
115115 -- init callback info
116+ local is_internal = self ._INTERNAL
116117 local callback = string ._dump (self ._CALLBACK )
117- local callinfo = {name = self :name (), argv = argv , internal = self . _INTERNAL }
118+ local callinfo = {name = self :name (), argv = argv , internal = is_internal }
118119
119120 -- we need a pipe pair to wait and listen thread exit event
120- local rpipe , wpipe = pipe .openpair (" AA" )
121- self ._RPIPE = rpipe
122- callinfo .wpipe = libc .dataptr (wpipe :cdata (), {ffi = false })
123- -- we need to suppress gc to free it, because it has been transfer to thread in another lua state instance
124- wpipe ._PIPE = nil
121+ if not is_internal then
122+ local rpipe , wpipe = pipe .openpair (" AA" )
123+ self ._RPIPE = rpipe
124+ callinfo .wpipe = libc .dataptr (wpipe :cdata (), {ffi = false })
125+ -- we need to suppress gc to free it, because it has been transfer to thread in another lua state instance
126+ wpipe ._PIPE = nil
127+ end
125128
126129 -- serialize and pass callback and arguments to this thread
127130 -- we do not use string.serialize to serialize callback, because it's slower (deserialize)
@@ -182,7 +185,7 @@ function _thread:wait(timeout)
182185
183186 local ok , errors
184187 local rpipe = self ._RPIPE
185- if rpipe then
188+ if rpipe and scheduler : co_running () then
186189 local buff = bytes (16 )
187190 local read , data_or_errors = rpipe :read (buff , 1 , {block = true , timeout = timeout })
188191 if read > 0 then
@@ -192,7 +195,7 @@ function _thread:wait(timeout)
192195 errors = data_or_errors
193196 end
194197 end
195- if not scheduler : co_running () then
198+ if not rpipe then
196199 local waitok , wait_errors = thread .thread_wait (self :cdata (), timeout )
197200 if ok == nil or ok > 0 then
198201 ok = waitok
@@ -857,7 +860,9 @@ function thread._run_thread(callback_str, callinfo_str)
857860 argv = callinfo .argv
858861 threadname = callinfo .name
859862 is_internal = callinfo .internal
860- wpipe = pipe .new (libc .ptraddr (callinfo .wpipe , {ffi = false }))
863+ if callinfo .wpipe then
864+ wpipe = pipe .new (libc .ptraddr (callinfo .wpipe , {ffi = false }))
865+ end
861866 end
862867 end
863868
0 commit comments