I'd say you shouldn't be calling setenv() at all once you've spawned threads.
I'd say you shouldn't be calling setenv() at all once you've spawned threads.
Or, you know, get a better C library. https://src.illumos.org/source/xref/illumos-gate/usr/src/lib...
I imagine that it is meant to convey that the quality is higher in this library than in GNU libc.
I think the gist of it is that unlike the glibc implementation, the Illumos implementation of getenv() is lock-free and thread-safe.
We really should have embraced a better primitive than "shared memory execution environment"
The alternative that I have seen be successful, is to achieve parallelism by forking separate processes wherever you would have spawned threads, and then communicate through shared memory regions.
It's a lot like having Rust-style unsafe blocks, in that you know that if you are having a thread-safety issue it will definitely be in one of the code sections where you are touching the shared memory region, and not anywhere else.
Obviously there's a higher startup cost for forking, but this makes it possible to gain parallelism without breaking all the thread-unsafe code that is certainly in an existing large project.
That's why I hate ZeroMQ. They spawn threads and do magics behind your back.
If you're using a library like that it comes with the territory, and you have to decide for yourself the cost-benefit of using non blocking sockets and async io yourself, or trust a library.
Much more fun to write these things yourself sometimes, but I find e.g. libevent a nice somewhere-in-between abstraction level I can be happy with.
"But Go compiled it just fine..."
In case you don't know, cross-building with GOOS/GOARCH will imply CGO_ENABLED=0 unless you also specify CC_FOR_${GOOS}_${GOARCH}; I cross-build most of my code for (and test it on) amd64, arm64, linux, openbsd, and darwin.
Go will sometimes link to the local libc for network-related functionality if you don't disable cgo.
Time, date, physical spellings, ... many things are locale dependant, but socket stuff?.
It comes as a Surprise!!, and not the good kind, to many a network programmer with just a few years under their belt to discover threaded networking can segfault because of this.
Once you know, you know and don't forget (until next time), but I suspect this was the motivation behind the blog posting, the principal of potentially most surprise.
But, yes, in general for libc, if the manpage didn't say it's thread-safe, it is unsafe.