I want to create a tool which analyzes a C program for critical sections during the compilation phase. I am looking for the right algorithm which would let me do this. It can be at any phase of the compiler.
Asked
Active
Viewed 512 times
-1
-
2Don't take this the wrong way, but just don't. You'd need to do control flow analysis, then analyse the memory shared at concurrent stages, then attempt to guess if a race condition would be caused. – slugonamission Oct 14 '12 at 21:42
-
Agree with @slugonamission. If there even a hint of a chance of concurrent access with unintended side effects, you must *assume* it *will* happen and code for it accordingly. Not knowing means not understanding the concurrency of your code, and nothing is a substitute for knowing the code. – WhozCraig Oct 14 '12 at 21:51
-
Also, I've just thought (I was tired last night). If you can actually run the code, give Valgrind (using Helgrind) a look. It's not a static analysis tool, but it may give you some decent insight. – slugonamission Oct 15 '12 at 09:35
1 Answers
4
You may be interested in this article “Static analysis of run-time errors in embedded real-time parallel C programs”.
The Frama-C plug-in mthread was developed simultaneously and independently. It works on comparable principles.
Each of the above two tools is man-years of work over an existing base that already represents at least ten man-years of work. As some have already commented, if you want to do anything significant and useful for the kind of moderately large program that you cannot just read to convince yourself that it is correct, you are going to have a lot of work.

Pascal Cuoq
- 79,187
- 7
- 161
- 281