Search for errors

Does it make sense to try to find problems with threads during compilation?

I am talking about data races, dead ends, damaged state, etc.

+4
source share
3 answers

Until this is compilation time, you can check out Helgrind :

Overview

Helgrind is a Valgrind tool for detecting synchronization errors in C, C ++ and Fortran, which use POSIX pthreads threading primitives.

The main abstractions in POSIX pthreads are: a set of threads, a common address space, a thread creation, a thread join, a thread exit, mutexes (locks), variable conditions (event notifications between threads), reader-writer locks, spin locks, semaphores and barriers.

Helgrind can detect three error classes, which are discussed in detail in the following three sections:

  • Misuse of the POSIX pthreads API.
  • Potential deadlocks due to locking ordering issues.
  • Mountains of data - access to memory without corresponding locking or synchronization.

Such problems often lead to irreproducible, time-dependent failures, blockages and other abnormal behavior, and can be difficult to find in another way.

Helgrind knows about all pthread abstractions and tracks their effects as accurately as possible. On x86 and amd64, it understands and partially handles implicit blocking arising from the use of LOCK prefix instructions.

Helgrind works best when your application uses only the POSIX API pthreads. However, if you want to use custom threading primitives, you can describe your Helgrind behavior using the ANNOTATE_ * macros defined in helgrind.h. This functionality was added in Valgrind Release 3.5.0, and is considered experimental.

Since Boost.Threads is based on POSIX pthreads (at least on Linux), I would assume that this would work for him as well.

+4
source

As long as I don’t know any compiler with explicit parameters for diagnosing flows, Coverity is a static analysis tool that provides checkers for concurrency problems that, if not executed at runtime, may be poorly comparable to compilation time, since the compiler is a tool , which before the code generation does some static analysis for the reliability of the arrival, and this looks like what you are looking for, not necessarily tied to compilation time, that is, before the code generation ...

If the static analysis tool understands concurrency primitives, then yes, it is possible that static analysis is for flow problems. Is the tool / compiler at the point where these problems are correctly pointed out, I am still experiencing.

NB: At work, we used Coverity for static analysis, but so far we have been working through all the "problems" indicated by the tool, we have not yet enabled concurrency checking, so I can not give any feedback on how well this works. As for other simpler checkers, they pointed to a bunch of urgent problems, as well as some harmless problems and several false positives. I hope to check the result of the concurrency check to evaluate its usefulness.

+2
source

You might want to take a look at http://software.intel.com/en-us/articles/debugging-threaded-applications/ . There is software dedicated to this task, for example http://software.intel.com/en-us/intel-thread-checker/ .

EDIT: Sorry, did not see you ask for a solution to compile. Perhaps this answer still matters.

+1
source

Source: https://habr.com/ru/post/1313614/


All Articles