Skip to content

Co‐routine Threading

Mikayla edited this page Dec 22, 2025 · 6 revisions

Warning

This page's documentation is currently being updated as part of #680. Some information may be inaccurate.

Application Pseudo-Threading

All applications except for the Supervisor utilize co-routines to act as a multi-threading system. There is one "main" co-routine on each of those devices that is responsible for handling the OS event queue, and then auxiliary co-routines for handling various tasks. This allows the auxiliary co-routines to run commands that would consume the event queue, namely Mekanism API calls. Bringing those functions out of the main co-routine means that it will always catch all the incoming events, rather than some of them being consumed by Mekanism functions waiting for task_complete events.

Main threads are always responsible for handling peripheral disconnect/reconnects, receiving modem messages, handling mouse events, stopping the system on terminate events, and handling watchdog, loop clock, and other timer events.

Note that terminate events are sometimes caught while doing peripheral related commands, due to receiving a terminate before the command has completed with task_complete. The PPM records this with a flag as it catches that error, then the main thread checks if the PPM reports that they system should terminate.

Reactor PLC

The reactor PLC has 5 co-routines running via the ComputerCraft parallel API:

  • Main Thread
  • RPS Thread
  • Communications Tx (Transmit) Thread
  • Communications Rx (Receive) Thread
  • Setpoint Control Thread

Main Thread

The PLC main thread is responsible for timer events, modem messages, peripheral connections and disconnections, mouse events, and terminate events. To instruct other threads, it sends information across command and data queues to prevent blocking the main thread. For example, it can trip a timeout RPS trip due to a watchdog event via smem.q.mq_rps.push_command(MQ__RPS_CMD.TRIP_TIMEOUT), which passes an RPS command across the message queue object that the RPS thread can look for. It also pushes parsed packets to the communications Rx queue as it receives modem messages, and updates device status and peripheral references on peripheral connect/disconnect events.

RTU Gateway

Homepage

  1. User Manual
    1. System Setup Guide
      1. Device Layout
        1. Coordinator Displays
      2. Connecting to Mekanism Machines
      3. Application Installation
        1. Space Requirements
        2. Installation
        3. Updating
        4. Uninstalling
      4. SCADA Network
        1. Network Channels
        2. Network Connectivity
      5. Setup & Configuration
        1. Supervisor Setup
        2. Coordinator Setup
        3. Reactor PLC Setup
        4. RTU Gateway Setup
      6. Initial Startup
    2. Configurator Tools
      1. Supervisor Configurator
      2. Coordinator Configurator
      3. Reactor PLC Configurator
      4. RTU Gateway Configurator
      5. Pocket Configurator
    3. Redstone Waste Setup Guide
    4. TL;DR Quickstart
    5. FAQ and Common Problems
    6. Colorblind Accessibility
    7. Annunciator Panels
    8. Alarms
    9. System Views
      1. Main View Screen
      2. Valve & Flow Screen
      3. Unit View Screens
    10. Operating Procedure
    11. Status Messages
    12. Glossary
  2. Computer Applications
    1. Reactor PLC
      1. Front Panel
      2. Non-Networked Mode
      3. RPS
      4. PLC Emergency Coolant
    2. RTU Gateway
      1. Front Panel
    3. Supervisory Computer
      1. Front Panel
    4. Coordinator Computer
      1. Front Panel
    5. Pocket
      1. Home and Navigation
      2. Connectivity
      3. Main Applications
      4. System Details and Testing
  3. Notable System Components
    1. Co-routine Threading
    2. Project File Layout/Overview
    3. PPM - Protected Peripherals Manager
    4. RSIO - Redstone I/O
    5. Utility Classes
    6. Networking
  4. Notes
    1. Known Issues
    2. Process Closed Loop Controller
    3. Project Files and Layout
    4. Alternative Installation Strategies
  5. Investigations
    1. Startup Rate High
    2. Reactor Temperature Calculation
  6. References & Resources
    1. CC: Tweaked Character Set
    2. Mekanism API Notes
    3. Design & Regulatory References
  7. Legacy
    1. coord.settings File
    2. config.lua Files
      1. Supervisor config.lua
      2. Coordinator config.lua
      3. Reactor PLC config.lua
      4. RTU Gateway config.lua

Clone this wiki locally