.. _particle-thread-safety-page:

#############
Thread Safety
#############

The :class:`ParticleDatasetReader <cee::pt::ParticleDatasetReader>` and :class:`PtfxDatasetWriter <cee::pt::PtfxDatasetWriter>`
classes are internally synchronized with a mutex, making them safe to call from multiple threads concurrently. Common
multi-threaded patterns include:

- Reading frames on a background thread while the main thread renders
- Calling :func:`preloadFrames() <cee::pt::ParticleDatasetReader::preloadFrames>` from a background thread
- Writing frames from a producer thread while another thread continues simulation

.. note::

    :class:`ParticleModel <cee::pt::ParticleModel>` itself must be accessed from the rendering thread (or with
    external synchronization), as it interacts with OpenGL state. Only the reader and writer are thread-safe
    internally.
