Due to this POSIX issue https://austingroupbugs.net/view.php?id=1845 FreeBSD libc now deliberately leaks a locked pthread_mutex to protect exit() https://github.com/freebsd/freebsd-src/commit/3f3ec4b99f79d32a0bf15495559ca9883bd751f2 musl libc may do something similar https://elixir.bootlin.com/musl/v1.2.5/source/src/exit/exit.c#L27 It uses some internal locking mechanism for some things but also a mutex and rwlock in __libc_exit_fini. No idea about other libc implementations for the moment.
It looks like glibc uses an intenral locking mechanism. https://sourceware.org/bugzilla/show_bug.cgi?id=31997 and https://sourceware.org/pipermail/libc-alpha/2024-July/158579.html
I've pushed a change that turns off this check for FreeBSD 15 and later. I don't consider that to be a definitive fix so I'm not closing this item.
commit 5c47ad94a0485cccd2a41506dd7e83f58b4569c3 (HEAD -> master, origin/master, origin/HEAD) Author: Paul Floyd <pjfloyd@wanadoo.fr> Date: Sun Nov 3 19:47:12 2024 +0100 Bug 494337 - All threaded applications cause still holding lock errors Don't count the first call to pthread_mutex_lock() from exit(). Needed to update a couple of expecteds as exit() is now wrapped so it turns up in the callstacks. This is only for FreeBSD.