OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogutil commits / 2c1c5a4

Revert "Rework barrier to take a factory function."
This reverts commit 2ffbf08490066a60d11739d7c60101af4301e9bd. This is spinning out of control. I have let Claude write this code, and I've been naively commiting the fixes, because they smelled OK, and I was trusting Claude to get it write. However, we are now on day three of debugging crashes and hangs in this new code. First step is to revert some of the increasingly baroque changes.
2c1c5a43e4317718d86d544fc4b837575db895af
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-07T17:56:37.000Z

Changed files (2) +14 -25

opencog/util/async_buffer.h +7 -13
……@@ -163,8 +163,7 @@ class async_buffer
163163 void insert(Element&&);
164164 void flush();
165165 void barrier(void);
166 template<typename Factory>
167 void barrier(Factory&& make_element);
166 void barrier(const Element&);
168167
169168 void set_watermarks(size_t, size_t);
170169 void stall(bool);
……@@ -437,23 +436,18 @@ void async_buffer<Writer, Element>::barrier()
437436 drain();
438437}
439438
440/// Barrier that ensures every worker processes a provided element.
439/// Barrier that ensures every worker processes the given element.
441440/// This first drains existing work queues, then gives each worker
442/// an element provided by the factory. It then waits for all
443/// workers to complete. This guarantees that every worker has run
444/// at least once.
445///
446/// The factory callable is invoked once per worker thread to create
447/// a unique element. Since the async_buffer is deduplicating for
448/// work elements, each element must be distinct.
441/// a copy of `elt` for processing. It then waits for all workers
442/// to complete. This guarantees that every worker has run at least
443/// once.
449444///
450445/// The intended use case for this function are systems that have
451446/// workers that do caching or lazy initialization or implement
452447/// other actions that require synchronization that the default
453448/// `barrier(void)` would miss.
454449template<typename Writer, typename Element>
455template<typename Factory>
456void async_buffer<Writer, Element>::barrier(Factory&& make_element)
450void async_buffer<Writer, Element>::barrier(const Element& elt)
457451{
458452 std::unique_lock<std::mutex> lock(_enqueue_mutex);
459453
……@@ -467,7 +461,7 @@ void async_buffer<Writer, Element>::barrier(Factory&& make_element)
467461
468462 // Enqueue one element for each thread.
469463 for (unsigned int i = 0; i < _thread_count; i++)
470 do_insert(make_element());
464 do_insert(elt);
471465
472466 // Wait for all threads to complete their barrier work
473467 completion.wait();
opencog/util/async_method_caller.h +7 -12
……@@ -135,8 +135,7 @@ class async_caller
135135 void enqueue(Element&&);
136136 void flush_queue();
137137 void barrier(void);
138 template<typename Factory>
139 void barrier(Factory&& make_element);
138 void barrier(const Element&);
140139
141140 void set_watermarks(size_t, size_t);
142141
……@@ -350,22 +349,18 @@ void async_caller<Writer, Element>::barrier()
350349 drain();
351350}
352351
353/// Barrier that ensures every worker processes an element.
352/// Barrier that ensures every worker processes the given element.
354353/// This first drains existing work queues, then gives each worker
355/// an element provided by the factory. It then waits for all
356/// workers to complete. This guarantees that every worker has run
357/// at least once.
358///
359/// The factory callable is invoked once per worker thread to create
360/// an element.
354/// a copy of `elt` for processing. It then waits for all workers
355/// to complete. This guarantees that every worker has run at least
356/// once.
361357///
362358/// The intended use case for this function are systems that have
363359/// workers that do caching or lazy initialization or implement
364360/// other actions that require synchronization that the default
365361/// `barrier(void)` would miss.
366362template<typename Writer, typename Element>
367template<typename Factory>
368void async_caller<Writer, Element>::barrier(Factory&& make_element)
363void async_caller<Writer, Element>::barrier(const Element& elt)
369364{
370365 std::unique_lock<std::mutex> lock(_enqueue_mutex);
371366
……@@ -381,7 +376,7 @@ void async_caller<Writer, Element>::barrier(Factory&& make_element)
381376 for (unsigned int i = 0; i < _thread_count; i++)
382377 {
383378 _pending ++;
384 _store_queue.push(make_element());
379 _store_queue.push(elt);
385380 _item_count++;
386381 }
387382