Skip to content

Commit 54c5dad

Browse files
authored
Merge pull request #181 from Chia-Network/EL.TSAN-false
Add some locking about stdout to avoid some false positives in TSAN
2 parents 4f2b3ec + 365be56 commit 54c5dad

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/vdf.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const int64_t EXP_THRESH = 31;
7373
// Notifies ProverManager class each time there's a new event.
7474
bool new_event = false;
7575
std::condition_variable new_event_cv;
76-
std::mutex new_event_mutex;
76+
std::mutex new_event_mutex, cout_lock;
7777

7878
bool debug_mode = false;
7979
bool fast_algorithm = false;
@@ -231,8 +231,12 @@ void repeated_square(form f, const integer& D, const integer& L,
231231
}
232232
#endif
233233
}
234+
{
235+
// this shouldn't be needed but avoids some false positive in TSAN
236+
std::lock_guard<std::mutex> lk(cout_lock);
237+
std::cout << "VDF loop finished. Total iters: " << num_iterations << "\n" << std::flush;
238+
}
234239

235-
std::cout << "VDF loop finished. Total iters: " << num_iterations << "\n" << std::flush;
236240
#ifdef VDF_TEST
237241
print( "fast average batch size", double(num_iterations_fast)/double(num_calls_fast) );
238242
print( "fast iterations per slow iteration", double(num_iterations_fast)/double(num_iterations_slow) );
@@ -266,7 +270,11 @@ Proof ProveOneWesolowski(uint64_t iters, integer& D, form f, OneWesolowskiCallba
266270
proof_serialized = SerializeForm(proof_form, d_bits);
267271
Proof proof(y_serialized, proof_serialized);
268272
proof.witness_type = 0;
269-
std::cout << "Got simple weso proof: " << proof.hex() << "\n";
273+
{
274+
// this shouldn't be needed but avoids some false positive in TSAN
275+
std::lock_guard<std::mutex> lk(cout_lock);
276+
std::cout << "Got simple weso proof: " << proof.hex() << "\n";
277+
}
270278
return proof;
271279
}
272280

0 commit comments

Comments
 (0)