Clang thread security analysis with C ++ standard library

It describes how a static thread safety analysis can be done with annotations in C ++: http://clang.llvm.org/docs/ThreadSafetyAnalysis.html

How can I use this with standard types like std :: mutex and std :: lock_guard?

The mutex.h sample code annotates the user interface. Do I have a "Mutex" type that is defined there and implements a class using std :: mutex with annotated methods, or does Clang somehow produce annotated types?

+4
source share
2 answers

clang , , std:: mutex, 15 , 2016.

clang std:: mutex std:: lock_guard, , . -Wthread-safety , .

. http://clang.llvm.org/docs/ThreadSafetyAnalysis.html.

-Wthread-safety .

+1

, mutex.h, std:: mutex. :

mutex.h std:: mutex

class CAPABILITY("mutex") Mutex {
private:
  std::mutex std_mutex;
public:
  // Acquire/lock this mutex exclusively.  Only one thread can have exclusive
  // access at any one time.  Write operations to guarded data require an
  // exclusive lock.

mutex.cpp

#include "mutex.h"

void Mutex::Lock(){
  this->std_mutex.lock();
}

void Mutex::Unlock(){
  this->std_mutex.unlock();
}

bool Mutex::TryLock(){
  return this->std_mutex.try_lock();
}
+2

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


All Articles