Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > detect non reentrant function

Thread Tools

detect non reentrant function

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

Reply With Quote
Antoninus Twink
Posts: n/a
On 8 Apr 2008 at 21:59, SHP wrote:
> 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.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can using "register" make code non-reentrant? Bob from Chesham Bois C++ 3 07-20-2009 11:23 AM
List of reentrant C library functions TheOne C Programming 9 11-29-2005 10:06 AM
List of reentrant C/C++ functions TheOne C++ 2 11-24-2005 10:59 AM
Compiler generator Coco/R: Reentrant version Hanspeter Moessenboeck Java 0 04-27-2005 11:42 AM
reentrant functions junky_fellow C Programming 6 10-31-2004 03:33 PM