boostorg / boostorg/statechart

Multiple orthogonal state components reacting to the same event can result in incorrect state transition

Open
#23 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
32
Forks
43
PR merge metrics
No merged PRs in 30d

Description

Consider an example state machine:
![orthogonal_regions](https://user-images.githubusercontent.com/8616371/189132048-25792a3f-4bb5-4169-a132-82f879cca68f.png)

```c++
#include
#include
#include
#include

#include

struct Main;
struct A0;
struct B0;
struct A1;
struct B1;

struct Event : boost::statechart::event {};
struct Machine : boost::statechart::state_machine {};
struct Main : boost::statechart::simple_state> {};


struct A0 : boost::statechart::simple_state>
{
using reactions = boost::statechart::transition;
A0() { std::cout << "Enter A0" << std::endl; }
~A0() { std::cout << "Exit A0" << std::endl; }
};

struct B0 : boost::statechart::simple_state>
{
B0() { std::cout << "Enter B0" << std::endl; }
~B0() { std::cout << "Exit B0" << std::endl; }
};

struct A1 : boost::statechart::simple_state>
{
using reactions = boost::statechart::transition;
A1() { std::cout << "Enter A1" << std::endl; }
~A1() { std::cout << "Exit A1" << std::endl; }
};

struct B1 : boost::statechart::simple_state>
{
B1() { std::cout << "Enter B1" << std::endl; }
~B1() { std::cout << "Exit B1" << std::endl; }
};


int main(int, char**)
{
Machine machine;
machine.initiate();
machine.process_event(Event {});

return 0;
}
```

Running the example outputs:
```
Enter A0
Enter A1
Exit A0
Enter B0
Exit A1
Exit B0
```

The machine transitions (A0, A1)->(B0, A1), although the correct transition is (A0, A1)->(B0, B1).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.