OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
IOThread.hpp File Reference

Separate IO writer thread with a bounded task queue (Phase 5, R17). More...

#include "WriteTask.hpp"
#include <thread>
#include <mutex>
#include <condition_variable>
#include <queue>
#include <atomic>
#include <functional>
Include dependency graph for IOThread.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  openswmm::IOThread
 Producer-consumer IO thread for writing simulation snapshots. More...
 

Namespaces

namespace  openswmm
 

Detailed Description

Separate IO writer thread with a bounded task queue (Phase 5, R17).

IOThread decouples simulation computation from output writing. The main simulation thread posts WriteTask objects; the IO thread drains them by calling PluginFactory::update_all() on each snapshot.

Producer / consumer model

Main thread (producer) IO thread (consumer)
───────────────────── ────────────────────
IOThread::post(snapshot) ──→ dequeue WriteTask
plugin_factory.update_all(task.snapshot)
IOThread::stop() ──→ finish queue, exit thread

Bounded queue

The queue capacity is configurable (default: 8 items). If the queue is full, post() blocks the main thread until space is available. This provides back-pressure if the IO thread is slower than the simulation.

Thread safety

  • post() is safe to call from any thread (typically main sim thread).
  • stop() must be called from the main thread exactly once.
  • start() must be called before post().
See also
WriteTask.hpp
src/engine/plugins/PluginFactory.hpp
docs/MASTER_IMPLEMENTATION_PLAN.md Phase 5
Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
License\n MIT License