3 ms·
You can use pthread_once() to simplify the initialization part: https://man.archlinux.org/man/pthread_once.3.en https://man.archlinux.org/man/pthread_once.3.en
by jcalvinowens 2y ago
You can use pthread_once() to simplify the initialization part: https://man.archlinux.org/man/pthread_once.3.en https://man.archlinux.org/man/pthread_once.3.en
I don't understand the desire not to link to pthread, it's about as ubiquitous as a library can be.
I doubt it's really a problem in this application... but naive userspace spinlocks are absolutely horrendous, see NOTES here: https://man.archlinux.org/man/pthread_spin_init.3.en https://man.archlinux.org/man/pthread_spin_init.3.en
User-space spin locks [...] are, by definition, prone to priority inversion and unbounded spin times. A programmer using spin locks must be exceptionally careful not only in the code, but also in terms of system configuration, thread placement, and priority assignment.