Browse Source

Merge branch 'bugfix_race_thrcreate' into bfgminer

Luke Dashjr 13 years ago
parent
commit
18948a9e02
1 changed files with 8 additions and 3 deletions
  1. 8 3
      miner.c

+ 8 - 3
miner.c

@@ -5443,9 +5443,10 @@ begin_bench:
 	k = 0;
 	k = 0;
 	for (i = 0; i < total_devices; ++i) {
 	for (i = 0; i < total_devices; ++i) {
 		struct cgpu_info *cgpu = devices[i];
 		struct cgpu_info *cgpu = devices[i];
-		cgpu->thr = malloc(sizeof(*cgpu->thr) * (cgpu->threads+1));
+		cgpu->thr = calloc(cgpu->threads+1, sizeof(*cgpu->thr));
 		cgpu->thr[cgpu->threads] = NULL;
 		cgpu->thr[cgpu->threads] = NULL;
 
 
+		// Setup thread structs before starting any of the threads, in case they try to interact
 		for (j = 0; j < cgpu->threads; ++j, ++k) {
 		for (j = 0; j < cgpu->threads; ++j, ++k) {
 			thr = &thr_info[k];
 			thr = &thr_info[k];
 			thr->id = k;
 			thr->id = k;
@@ -5465,6 +5466,12 @@ begin_bench:
 				tq_push(thr->q, &ping);
 				tq_push(thr->q, &ping);
 			}
 			}
 
 
+			cgpu->thr[j] = thr;
+		}
+
+		for (j = 0; j < cgpu->threads; ++j) {
+			thr = cgpu->thr[j];
+
 			if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr))
 			if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr))
 				continue;
 				continue;
 
 
@@ -5486,8 +5493,6 @@ begin_bench:
 
 
 			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
 			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
 				quit(1, "thread %d create failed", thr->id);
 				quit(1, "thread %d create failed", thr->id);
-
-			cgpu->thr[j] = thr;
 		}
 		}
 	}
 	}