protofsm: add thread-safe IsRunning method to StateMachine#9883
protofsm: add thread-safe IsRunning method to StateMachine#9883guggero merged 1 commit intolightningnetwork:masterfrom
Conversation
This commit introduces a new `IsRunning()` method to the `StateMachine`. This method allows callers to safely query whether the state machine is currently active after it has been started and before it has been stopped. To ensure thread-safety, the internal `running` status flag is implemented using `atomic.Bool` (from `sync/atomic`). Without atomic operations, concurrent accesses to a simple boolean flag from different goroutines (e.g., one goroutine calling `IsRunning()` while another executes `Start()` or `Stop()`) could lead to stale reads or data races.
|
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This commit introduces a new
IsRunning()method to theStateMachine. This method allows callers to safely query whether the state machine is currently active after it has been started and before it has been stopped.To ensure thread-safety, the internal
runningstatus flag is implemented usingatomic.Bool(fromsync/atomic). Without atomic operations, concurrent accesses to a simple boolean flag from different goroutines (e.g., one goroutine callingIsRunning()while another executesStart()orStop()) could lead to stale reads or data races.