Draw/design a state machine with multiple threading

finite-state machineuml

I'm developing a module, which is very complicated. I'm trying to draw a state machine but I don't know if a state machine can present multiple threading cases.

Basically, the module processes the multi-threading inputs. For example, if input a and input b are coming together, the state would change from stateA to stateB. If input a is coming alone, the state would change from stateA to stateC. If input a has entered into the module and it is being processed by the module while input b is coming, the state would change from stateA to stateD.

In this case, I don't know how to present these different situations in a state machine.

Best Answer

Forget the notion of events coming at the same time. This doesn't happen in reality (notwithstanding contrived thought experiments involving general relativity.)

Every input event may lead to a state change and additional actions. If you want to handle events while processing of previous events is still happening, introduce an intermediate state stateA_inProgress in which b events lead to stateD.

If you want to handle events a and b happening closely together in time (that's the best approximation we have for "at the same time") then you need to enter a waiting state and start a timer when the first event happens, and switch to the respective target state when either the timer expires or the second input event arrives.

However, it is unlikely that you really need this. If you could edit your question to state the actual problem you're trying to solve, it might be easier to find a solution. As it stands, this looks like either an XY problem or a hypothetical question without sufficient understanding of state machines.

Related Topic