-
Type:
Task
-
Resolution: Declined
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Server Programmability
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Currently in our code base we use RAII types to acquire mutexes and other locks (like RSTL, Global, etc). This unfortunately means that from a stack trace, it's not obvious whether a thread is holding a lock or where exactly it acquired a lock if it is holding one. For example, suppose we have this code:
void a() {
stdx::lock_guard<stdx::mutex> lk(_mutex);
b();
}
void b() {
c();
}
void c() {
printStackTrace();
}
The stack trace at c() looks like:
c() line 60 b() line 40 a() line 20
This doesn't tell us any info on whether the thread is holding any locks or which locks it's holding.
An alternative API for lock acquisition would be to have a function called acquireReplCoordMutexAndDoWork(func work). Our code would then look like this:
void acquireReplCoordMutexAndDoWork(func work) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
work();
}
void a() {
acquireReplCoordMutexAndDoWork(b);
}
// other functions look the same
Therefore, the stack trace now would look like this, which makes it very obvious which thread is holding the lock:
c() line 60 b() line 40 acquireReplCoordMutexAndDoWork() line10 a() line 20
This would be extremely helpful when investigating deadlocks because from a stack trace we'd be able to see which threads are holding which locks.