Updated Threading (markdown)

Mikayla 2023-12-13 16:23:02 -05:00
parent 1fd2fc2d86
commit b20a3acdb0

@ -1,6 +1,6 @@
# Reactor PLC and RTU Pseudo-Threading # Reactor PLC and RTU Gateway Pseudo-Threading
The PLC and RTUs 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. The PLC and RTU gateways 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. 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.
@ -19,3 +19,5 @@ The reactor PLC has 5 co-routines running via the ComputerCraft `parallel` API:
### Main 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. 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