Crash when using std.Thread in a static library and not linking LibC

In my static library I need to spawn some threads, so I use the thread pool from std.
Then I link the library to my main.zig. If I run the program without linking libC, it crashes, due to std.linux.tls.area_desc.alignment == 0 when spawning a thread. I suspect that these values are not initialized when libC is not linked.

Is it possible to use the thread pool without linking libC?

1 Like

I think this is a known issue: Thread local storage implementation on Linux uses global state which is not initialized when using zig build-lib · Issue #17062 · ziglang/zig · GitHub

Seems like the linker doesn’t set up thread local storage correctly.

So no, currently you can’t use threads on Linux in a library without linking libc

2 Likes

We can’t use thread pool on linux without libc

I am not sure that it’s true for thread usage

I am using threads in most of my projects without libc

1 Like