Never wait indefinitely for a pthread conditional in the hash_pop loop in case the work scheduler misses the last wakeup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/cgminer.c b/cgminer.c
index cdbf701..0f0504e 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5915,26 +5915,21 @@ static struct work *hash_pop(void)
mutex_lock(stgd_lock);
while (!HASH_COUNT(staged_work)) {
- if (!no_work) {
- struct timespec then;
- struct timeval now;
- int rc;
+ struct timespec then;
+ struct timeval now;
+ int rc;
- cgtime(&now);
- then.tv_sec = now.tv_sec + 10;
- then.tv_nsec = now.tv_usec * 1000;
- pthread_cond_signal(&gws_cond);
- rc = pthread_cond_timedwait(&getq->cond, stgd_lock, &then);
- /* Check again for !no_work as multiple threads may be
- * waiting on this condition and another may set the
- * bool separately. */
- if (rc && !no_work) {
- no_work = true;
- applog(LOG_WARNING, "Waiting for work to be available from pools.");
- }
- } else {
- pthread_cond_signal(&gws_cond);
- pthread_cond_wait(&getq->cond, stgd_lock);
+ cgtime(&now);
+ then.tv_sec = now.tv_sec + 10;
+ then.tv_nsec = now.tv_usec * 1000;
+ pthread_cond_signal(&gws_cond);
+ rc = pthread_cond_timedwait(&getq->cond, stgd_lock, &then);
+ /* Check again for !no_work as multiple threads may be
+ * waiting on this condition and another may set the
+ * bool separately. */
+ if (rc && !no_work) {
+ no_work = true;
+ applog(LOG_WARNING, "Waiting for work to be available from pools.");
}
}