Commit b74b54d95b9ba916dff52a87076279cfbfd9028a

Con Kolivas 2012-08-23T11:09:09

Check we haven't staged work while waiting for a curl entry before proceeding.

diff --git a/cgminer.c b/cgminer.c
index 9162e6a..ef18bdb 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2421,13 +2421,18 @@ retry:
 			lagging = true;
 		pool = ret_work->pool = select_pool(lagging);
 
+		inc_queued();
+
 		if (!ce)
 			ce = pop_curl_entry(pool);
 
-		/* Inc queued count after ce is popped in case there're none
-		 * left and we think we've queued work when we're just waiting
-		 * for curls */
-		inc_queued();
+		/* Check that we haven't staged work via other threads while
+		 * waiting for a curl entry */
+		if (total_staged() >= maxq) {
+			dec_queued();
+			free_work(ret_work);
+			goto out;
+		}
 
 		/* obtain new work from bitcoin via JSON-RPC */
 		if (!get_upstream_work(ret_work, ce->curl)) {