Skip to content

The thread:alive() method may not work #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
javalikescript opened this issue Apr 4, 2025 · 1 comment · May be fixed by #23
Open

The thread:alive() method may not work #22

javalikescript opened this issue Apr 4, 2025 · 1 comment · May be fixed by #23

Comments

@javalikescript
Copy link

Depending on the pthread implementation, the thread:alive() method may not work.

Existing implementations vary on the result of a pthread_kill() with a thread ID indicating an inactive thread (a terminated thread that has not been detached or joined). Some indicate success on such a call, while others give an error of [ESRCH].

The glibc seems to return success since 2.34

@javalikescript javalikescript linked a pull request Apr 4, 2025 that will close this issue
@javalikescript
Copy link
Author

Could be reproduced with the following code.

local llthreadsLib = require('llthreads')
local luaSocketLib = require('socket')

local t = llthreadsLib.new([[
    luaSocketLib = require('socket')
    luaSocketLib.sleep(1)
    print('ended')
]])
t:start(false, true)

for i = 1, 5 do
    print('alive', t:alive())
    luaSocketLib.sleep(0.5)
end

print('join', t:join())

Which results in

lua work/llthread.lua 
alive   true
alive   true
ended
alive   true
alive   true
alive   true
join    true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant