analyzer icon indicating copy to clipboard operation
analyzer copied to clipboard

Detect calls of thread-unsafe functions as races

Open sim642 opened this issue 3 years ago • 1 comments

Under "Thread-safe functions" of pthreads man page, it says the following:

A thread-safe function is one that can be safely (i.e., it will deliver the same results regardless of whether it is) called from multiple threads at the same time. POSIX.1-2001 and POSIX.1-2008 require that all specified in the standard shall be thread-safe, except for following functions:

Then a list of possibly thread-unsafe functions follows.

We should consider calls to these functions (in place of global variables) and report racing calls (in place of accesses).

I was reminded of this when trying to figure out why chrony uses a global lock to protect what seems to be thread-local data manipulation. It doesn't call any functions from this list, but for completenes it would be nice to detect as well.

sim642 avatar May 04 '22 17:05 sim642

Related to a couple of *_unlocked functions from the list, turns out there are flockfile, ftrylockfile and funlockfile, which treat a FILE as a mutex. No idea, if anyone uses them, but I guess it wouldn't hurt to also consider those for mutual exclusion.

sim642 avatar May 04 '22 17:05 sim642

Related to a couple of *_unlocked functions from the list, turns out there are flockfile, ftrylockfile and funlockfile, which treat a FILE as a mutex. No idea, if anyone uses them, but I guess it wouldn't hurt to also consider those for mutual exclusion.

Should we move this to a new issue?

michael-schwarz avatar Sep 11 '23 09:09 michael-schwarz