detect non reentrant function

S

SHP

Hi
It there a way to detect non reentrant or thread unsafe function
usage at compile time? Any option in gcc?

thanks
shekhar
 
A

Antoninus Twink

Hi
It there a way to detect non reentrant or thread unsafe function
usage at compile time? Any option in gcc?

The compiler might be able to prove that some functions are thread-safe:
for example, it can know that a function is pure if it doesn't reference
static or global variables (only automatic variables, which are kept
within its stack frame), doesn't use pointers, and only uses pure
standard library functions.

Similarly, it can know that some functions are thread-unsafe: for
example, a function that modifies a global variable without first
locking a mutex.

But for most functions, it will be completely impossible for the
compiler to know whether they are thread-safe or not. As soon as a
function calls another function that's defined in some external library
(which may not even be written in C, even if the source code is
available), what possible hope is there for the compiler to decide
whether it's thread-safe?

I don't know how sophisticated static analysis tools have become in
trying to decide thread-safety, if that's your question, but they
certainly can't always succeed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top