Skip to content

Commit

Permalink
__stdio_exit.c: use normal file locking for now
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yamt committed Dec 13, 2022
1 parent a6e91a7 commit 0349c54
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libc-top-half/musl/src/stdio/__stdio_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ weak_alias(dummy_file, __stderr_used);
static void close_file(FILE *f)
{
if (!f) return;
#ifdef __wasilibc_unmodified_upstream
FFINALLOCK(f);
#else
FLOCK(f);
#endif
if (f->wpos != f->wbase) f->write(f, 0, 0);
if (f->rpos != f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR);
#ifndef __wasilibc_unmodified_upstream
FUNLOCK(f);
#endif
}

void __stdio_exit(void)
Expand Down

0 comments on commit 0349c54

Please sign in to comment.