-
Notifications
You must be signed in to change notification settings - Fork 199
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
__stdio_exit.c: use normal file locking for now #363
Conversation
Unlike many of platforms with threads/lwps, wasi doesn't have separate api for thread exit and process exit as of writing this. It only has a single `wasi_proc_exit`, which is currently used for both of process exit and thread exit by wasi-libc. Becasue of that, on wasi, exit(3) only terminates the calling thread. On the other hand, the stdio exit logic uses FFINALLOCK macro, which leaves the file locked. While it's fine on platforms where exit somehow forcibly terminates other threads soon, it can make other threads block on these locks forever on wasi. Until the situation is cleaned up, this commit makes stdio exit use normal file locking instead of the "final" variant. This change allows other threads to continue running. Hopefully those threads will exit by themselves soon. cf. WebAssembly/wasi-threads#7
I think IIUC, the semantics of If threads continue after exit then other bad things can happen, not just the use of closed files. We run other destruction stuff on exit too: wasi-libc/libc-top-half/musl/src/exit/exit.c Lines 41 to 52 in a6e91a7
|
i agree it's what the name but it's less clear to me what also, "kill other thread" is a somehow new concept to implement.
although i feel it's widely used api, it's a valid option.
is it explicitly stated in some spec?
sure. even if those threads do nothing particularly bad, running threads itself is a bad thing. |
In emscripten this is implemented by sending and message back to the main thread that can then terminate all the workers. i.e. there is a main thread that manages all the pthread workers, and it is in charge of creating new ones and destroying all of them on program exit.
|
ok. i didn't know that. thank you.
ok
|
i implemented in the "proc_exit terminates all threads" semantics in an engine and confirmed this change is not necessary. |
Unlike many of platforms with threads/lwps, wasi doesn't have separate api for thread exit and process exit as of writing this. It only has a single
wasi_proc_exit
, which is currently used for both of process exit and thread exit by wasi-libc. Becasue of that, on wasi, exit(3) only terminates the calling thread.On the other hand, the stdio exit logic uses FFINALLOCK macro, which leaves the file locked. While it's fine on platforms where exit somehow forcibly terminates other threads soon, it can make other threads block on these locks forever on wasi.
Until the situation is cleaned up, this commit makes stdio exit use normal file locking instead of the "final" variant. This change allows other threads to continue running. Hopefully those threads will exit by themselves soon.
cf. WebAssembly/wasi-threads#7