Semaphore potentially may underflow and become negative
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
DC++ |
Fix Released
|
Medium
|
Unassigned | ||
LinuxDC++ |
Confirmed
|
Medium
|
Unassigned |
Bug Description
As noted in POSIX about pthread_cond_wait, spurious wakeup may occur and predicate should be rechecked after wakeup.
So the patch.
diff --git a/client/
index f89148d..b0c59e5 100644
--- a/client/
+++ b/client/
@@ -61,7 +61,7 @@ public:
bool wait() throw() {
- if(count == 0) {
+ while (count == 0) {
}
@@ -76,7 +76,10 @@ public:
- int ret = pthread_
+ int ret;
+ do {
+ ret = pthread_
+ } while (ret==0 && count==0);
Related branches
- LinuxDC++ Team: Pending requested
-
Diff: 489 lines (+171/-91)12 files modifieddcpp/Atomic.h (+122/-0)
dcpp/BufferedSocket.cpp (+3/-3)
dcpp/BufferedSocket.h (+5/-1)
dcpp/Client.cpp (+6/-6)
dcpp/Client.h (+14/-6)
dcpp/CriticalSection.h (+7/-27)
dcpp/Pointer.h (+4/-4)
dcpp/Semaphore.h (+5/-2)
dcpp/ShareManager.cpp (+3/-3)
dcpp/ShareManager.h (+2/-1)
dcpp/Thread.cpp (+0/-4)
dcpp/Thread.h (+0/-34)
- Jacek Sieka: Needs Information
-
Diff: 408 lines (+171/-53)10 files modifieddcpp/Atomic.h (+122/-0)
dcpp/BufferedSocket.cpp (+3/-3)
dcpp/BufferedSocket.h (+5/-1)
dcpp/Client.cpp (+6/-6)
dcpp/Client.h (+14/-6)
dcpp/CriticalSection.h (+7/-27)
dcpp/Pointer.h (+4/-4)
dcpp/Semaphore.h (+5/-2)
dcpp/ShareManager.cpp (+3/-3)
dcpp/ShareManager.h (+2/-1)
True. And this seems to affect the dev version also. I assume (from the fact that there's still client dir) this was from/for the 1.0.3?
--RZ