Clang thread security analysis and thread roles

Thread safety analysis clang docs and paper Suppose that you can specify that specific functions will be called only by specific threads. From the article:

#include "ThreadRole.h"

ThreadRole InputThread;
ThreadRole GUIThread;

class Widget {
public :
    virtual void onClick() REQUIRES(InputThread);
    virtual void draw() REQUIRES(GUIThread);
};

class Button : public Widget {
public :
    void onClick() override {
        depressed = true;
        draw() ; // WARNING!
    }
};

However, none of them indicate how you actually comment on ThreadRolethis to happen. What should look like ThreadRoleto make this work?

+4
source share
1 answer

Relevant: https://insights.sei.cmu.edu/sei_blog/2014/10/thread-safety-analysis-in-c-and-c.html typedef int __attribute__((capability("role"))) ThreadRole; ThreadRole FlightControl, Logging; void acquire(ThreadRole R) __attribute__((acquire_capability(R))) __attribute__((no_thread_safety_analysis)) {} void release(ThreadRole R) __attribute__((release_capability(R))) __attribute__((no_thread_safety_analysis)) {} ...

0
source

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


All Articles