dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.41k stars 197 forks source link

NativeAOT-LLVM: Review decision to include pthreads in WASI build and Wait #2295

Open yowl opened 1 year ago

yowl commented 1 year ago

I've been regretting my decision to use pthreads in WASI, so was looking again at going to the non-pthreads configuration of the Wasi-SDK.

What would be a good approach to deal with things like

https://github.com/dotnet/runtimelab/blob/588b1e37a5caeefd187bc8ddc2e4735c3da2c183/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp#L219

It uses pthread_mutex_lock so is a problem.

Any thoughts on these options:

Thanks,

cc @dotnet/nativeaot-llvm

yowl commented 1 year ago

Another option

SingleAccretion commented 1 year ago

What does the Browser build do, and how much shimming is needed to make this work?

It seems like there are two options, broadly: 1) Implement PAL-level functions and constructs for a single-threaded environment. 2) Shim pthread APIs for a single-threaded environment - logically copy what Emscripten does.

pthread is lower-level than PAL so it is in some sense easier to shim it, but if all of it needs shimming, that becomes less attractive.

yowl commented 1 year ago

Emscripten stubs it. It starts here with the PTHREADS option setting is_mt

https://github.com/emscripten-core/emscripten/blob/96a832cee0cb3c028687dd03fa761264c67bf7b9/tools/system_libs.py#L703

In the same file, this brings in the stubs

https://github.com/emscripten-core/emscripten/blob/96a832cee0cb3c028687dd03fa761264c67bf7b9/tools/system_libs.py#L1120

Where __pthread_mutex_timedlock is stubbed

https://github.com/emscripten-core/emscripten/blob/96a832cee0cb3c028687dd03fa761264c67bf7b9/system/lib/pthread/library_pthread_stub.c#LL78C1-L82C1

I will see how many of these we would need.

SingleAccretion commented 1 week ago

Fixed in #2317.