-
Notifications
You must be signed in to change notification settings - Fork 17
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
Updates in synchronization mutex for Shared data #276
Updates in synchronization mutex for Shared data #276
Conversation
Add guarded by and lock required annotations
CCriticalSection cs_totalBytesRecv; | ||
CCriticalSection cs_totalBytesSent; | ||
Mutex cs_totalBytesRecv; | ||
Mutex cs_totalBytesSent; |
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.
In Bitcoin, RecursiveMutex is used.
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.
they have only one mutex. other is changed to atomic
// Network usage totals
mutable Mutex m_total_bytes_sent_mutex;
std::atomic<uint64_t> nTotalBytesRecv{0};
```
src/net.h
Outdated
CCriticalSection cs_vRecv; | ||
RecursiveMutex cs_vSend; | ||
RecursiveMutex cs_hSocket; | ||
RecursiveMutex cs_vRecv; |
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.
In Bitcoin, Mutex is used.
std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes); | ||
CCriticalSection cs_vAddedNodes; | ||
Mutex cs_vAddedNodes; |
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.
In Bitcoin, RecursiveMutex is used.
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 remains the same:
mutable Mutex m_added_nodes_mutex;
bool setBannedIsDirty; | ||
bool fAddressesInitialized; | ||
CAddrMan addrman; | ||
std::deque<std::string> vOneShots; | ||
CCriticalSection cs_vOneShots; | ||
Mutex cs_vOneShots; |
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.
In Bitcoin, RecursiveMutex is used.
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 renamed. Bitcoin has reimplemented the peer management layer.
Mutex m_addr_fetches_mutex;
@@ -530,7 +530,7 @@ struct LocalServiceInfo { | |||
int nPort; | |||
}; | |||
|
|||
extern CCriticalSection cs_mapLocalHost; | |||
extern Mutex cs_mapLocalHost; |
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.
In Bitcoin, RecursiveMutex is used.
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.
extern GlobalMutex g_maplocalhost_mutex;
you mean they say globalmutex which is actually
class GlobalMutex : public Mutex { };
cs_sendProcessing needs to be recursive. otherwise it causes deadlocks
Changed CCriticalSections to Mutex and RecursiveMutex as in Bitcoin.
Add GUARDED_BY and EXCLUSIVE_LOCK_REQUIRED annotations to some shared data only.
Adding them to all shared data and functions caused lots of build errors on macOS. Clang supports static analysis for thread safety with option -thread-safety-analysis. But this does not seem to be strong enough to identify scope. i.e. when lock is outside a class or a function where the data is accessed. As most of our data and locks are global, and locking is in the outer scope, it causes lots of false positives. Adding more LOCKS in the same scope to pass the compilation warning causes deadlock in our tests.