OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogutil commits / a554160

Redo pending correctly, also.
a554160f3d63b1ca87a1004f276a5eb1f83d1b63
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-07T20:01:11.000Z

Changed files (1) +17 -7

opencog/util/async_buffer.h +17 -7
……@@ -334,9 +334,14 @@ void async_buffer<Writer, Element>::stop_writer_threads()
334334
335335 _stopping_writers = true;
336336
337 // Wait until the writer threads are (mostly) done.
338 while (0 < _pending)
339 std::this_thread::sleep_for(std::chrono::milliseconds(1));
337 // Wait until the writer threads are (mostly) done. There
338 // might still be some lingering enqueues after this exits.
339 unsigned long pend = _pending.load();
340 while (pend != 0)
341 {
342 _pending.wait(pend);
343 pend = _pending.load();
344 }
340345
341346 // Now tell all the threads that they are done.
342347 // I.e. cancel all the threads.
……@@ -491,8 +496,10 @@ void async_buffer<Writer, Element>::write_loop()
491496 _busy_writers ++;
492497 (_writer->*_do_write)(elt);
493498 _busy_writers --;
494 _pending --;
495 _pending.notify_all();
499
500 unsigned long old_pend = _pending.fetch_sub(1);
501 if (1 == old_pend)
502 _pending.notify_all();
496503 }
497504 catch (typename concurrent_set<Element>::Canceled& e)
498505 {
……@@ -506,7 +513,7 @@ void async_buffer<Writer, Element>::write_loop()
506513
507514 // barrier() will drop the count to zero after
508515 // all workers have run.
509 unsigned cnt = _barrier_count.load();
516 unsigned int cnt = _barrier_count.load();
510517 while (0 < cnt)
511518 {
512519 _barrier_count.wait(cnt);
……@@ -533,7 +540,10 @@ void async_buffer<Writer, Element>::do_insert(Element&& elt)
533540 if (not inserted)
534541 {
535542 _duplicate_count++;
536 _pending --;
543
544 unsigned long old_pend = _pending.fetch_sub(1);
545 if (1 == old_pend)
546 _pending.notify_all();
537547 }
538548}
539549