Can external locking be used make the state machine truly thread-safe? #596
Replies: 2 comments
-
Yep, if you funnel every interaction with the state machine through a lock, that will effectively serialize all operations and be thread-safe. Just note that this only works for the synchronous
Are other threads touching any part of the state machine outside of the lock? Because you can still get weird behaviour if you're interacting with memory that the state machine is also interacting with, unless you also put a lock around that. |
Beta Was this translation helpful? Give feedback.
-
No. No other threads are doing that. After startup, configuring the states, and calling But since I was unsure about the answer I would get here, yesterday I actually went ahead and created a class derived from From what you are saying it sounds like I don't need it. As long as I stick with |
Beta Was this translation helpful? Give feedback.
-
I understand that Stateless is not designed to be used from multiple threads. But even after reading the lengthy discussion about the issue here, I am still unclear on one point:
If I use the
StateMachine
simultaneously from multiple threads withFiringMode.Queued
but I protect every single call to theFire()
function with a simple lock like so...Does that make my code thread safe? Would any problems still remain? Because frankly, that's what I am doing and it seems to work perfectly.... almost all the time. And I am unable to determine if that "almost" is due to other bugs of mine or the fact that what I'm doing is still not safe.
Beta Was this translation helpful? Give feedback.
All reactions