-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update net_plugin to support clang Thread Safety Analysis features #1268
Conversation
libraries/libfc/include/fc/mutex.hpp
Outdated
@@ -0,0 +1,227 @@ | |||
#ifndef THREAD_SAFETY_ANALYSIS_MUTEX_HPP | |||
#define THREAD_SAFETY_ANALYSIS_MUTEX_HPP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole file is unfortunate. I would have expected clang to provide this on the std mutex classes.
Actually it looks like it does: https://reviews.llvm.org/D14731
Can you just remove this fc wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only if we use the clang libc++
. Typically we build with gnu's libstdc++
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we don't need it. As long as we have one build that checks this, then we don't need these wrappers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that by default, clang uses the system's default c++ library (see this, and this seems to be the case on my ubuntu system - using GNU's libstdc++), in which case we wouldn't be using LLVM's libc++ even when building with clang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be worth a dedicated build to avoid having to provide these wrappers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The endgame is that we run a clang+libc++ build as part of CI, so if that is sufficient I do agree these wrappers are annoying goop. I'm not entirely following if the latest clang+libc++ works though, for example what does this comment mean
In addition even libc++ does not consistently provide these attributes on the mutex objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this comment mean
in libcxx, you can see that lock_guard has the attributes, but unique_lock doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in mutex only scoped_lock
has the attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it may be worth reflecting on why the feature has been described as "mature enough to be deployed in an industrial setting" for over 6 years, yet LLVM has neglected to integrate it fully in to their own stdlib in that time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the expectation is that people will write their own wrappers. It is necessary anyways if you use clang with the default c++ stdlib from the system (could be gnu on ubuntu, Microsoft's on windows), so providing your own wrappers guarantees that you benefit from the Thread Safety Analysis when building with clang, regardless of which stdlib you use.
in the doc, they write:
Thread safety analysis can be used with any threading library, but it does require that the threading API be wrapped in classes and methods which have the appropriate annotations. The following code provides mutex.h as an example; these methods should be filled in to call the appropriate underlying implementation.
Is ci/cd not running because of the conflict or some other reason? |
yeah conflicts prevent CI from running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrapping of shared_lock can come in when applied to whole repo.
Resolves #1230
Newer versions of clang support a Google developed tool called "Thread Safety Analysis". Here is the doc.
Thread safety analysis works very much like a type system for multi-threaded programs. In addition to declaring the type of data (e.g. int, float, etc.), the programmer can (optionally) declare how access to that data is controlled in a multi-threaded environment. For example:
The analysis is completely static (i.e. compile-time); there is no run-time overhead. I think our code robustness would greatly benefit to have these checks occur whenever the code is compiled with clang. In addition, these attributes are a useful documentation of the expected access controls.
This PR adds the access annotations for
net_plugin
.I had to change the calling parameters for
sync_manager::request_next_chunk()
. Unfortunately there is an issue in the thread safety analysis code which issues incorrect warnings when a class managing locksadopts
a lock. I submitted a LLVM issue for this.