thread-safety analysis tool?

Does the Studio toolset include anything like a static thread-safety

analysis? I'm thinking of something that would precede even the use

of lock_lint and Data Race Detection Tool.

I'm building a complicated multi-threaded application, and frankly it's

a pain to go looking up every routine I might call to verify its MT-safe

characteristics. I'm also a bit nervous about calling libraries whose

source code I don't control. It would be a Good Idea (TM) if there were

a tool that could crawl my source code and tell me what library routines

I'm calling that might not be totally thread-safe according to their man

pages. The tool could classify them as MT-Safe, Async-signal-safe, etc.

Then I could concentrate my development time on just those routines that

do need my attention.

Think of this as a kind of intermediate lint analysis, halfway in

complexity between lint itself and lock_lint. Yes, it would be an

imperfect analysis, but it would be better than nothing.

Desired options:

(1) Invest some effort in code-path analysis, to reduce the number of

false positives by ignoring routines called by the main thread before

any other threads are spawned, or called only by one thread.

(2) Analyze each library this program links to, first to simply report

all non-thread-safe APIs being called from the library, and then

potentially to analyze which routines from the library actually

get called (perhaps recursively) from my code, again to reduce the

number of false possitives. One can imagine an option to use an

associated descriptive file, akin to a lint library, to assist in

this process.

(3) Have options to include in the analysis particular libraries that

might be linked to at run time to via dlopen(), that the tool wouldn't

find by simple static analysis.

(4) Thread-safety profiles could be developed for alternative environments,

for example for different versions of Solaris, or for different versions

of Linux. This would assist greatly in porting programs.

Complications:

(1) Some routines might be thread-safe they way they are used by a

single thread; see what the man page has to say about readdir()

and readdir_r(), for instance.

(2) Some routines might be thread-safe as individual functions, but

their use with other routines must be carefully coordinated so as

not to confuse shared state. An example would be calling openlog()

and closelog() from different threads and still expecting syslog()

to work throughout.

Has anyone thought of such a tool before?

[2743 byte] By [herteg] at [2007-11-26 10:29:12]
# 1

I've been pestering the projects around me to work on something

like this for a while now.It's a really hard problem to try to do

this in a way that works for C, C++ and Fortran. Or even C and C++ since

they are separate compilers for us. It would be pretty straight forward

to extend lint in the same way it was extended for security checking.

We could have it flag all mt-unsafe routines as lint errors, if you supply

a -mt flag. But that would only work for C source code.

If you separate your source code into MT and non-MT then you could

omit the -mt flag on the single-threaded source files. And you can

always use lint-suppression comments in cases where you know

the MT-unsafe functions are called from some singled-threaded code.

So I think a lint-extension seems like a useful stepping stone until we get

a better tool. Do you think that smaller level of support would be useful?

--chris

ChrisQuenelle at 2007-7-7 2:34:47 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
I have filed a bug with your writeup in it. The bug ID is 6476870 andit should be visible in a day or two on bugs.sun.com. You'll beable to track the progress of this RFE. (If any progress happens ;-/,I can't make any promises.)--chris
ChrisQuenelle at 2007-7-7 2:34:47 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

> So I think a lint-extension seems like a useful stepping stone until we get

> a better tool. Do you think that smaller level of support would be useful?

I'm writing in C++, so something C-specific wouldn't cover my direct needs.

I know this tool is a hard problem, but frankly I'd rather skip the stepping

stone unless it could help in convincing people that the more general tool

ought to be built.

Thanks for filing the RFE; that's pretty much what I was hoping for. Even if

the tool takes a few years to materialize, the longest journey ...

herteg at 2007-7-7 2:34:47 > top of Java-index,Development Tools,Solaris and Linux Development Tools...