Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatching events in separate thread spawned from action? #583

Open
lambdaknight opened this issue Jul 25, 2023 · 0 comments
Open

Dispatching events in separate thread spawned from action? #583

lambdaknight opened this issue Jul 25, 2023 · 0 comments

Comments

@lambdaknight
Copy link

I was playing with one of your tests and trying to do something and ran into a problem.

struct c {
    auto operator()() noexcept {
        using namespace sml;
        // clang-format off
        return make_transition_table(
            * "s1"_s + on_entry<sml::initial> / [this] { calls += "s1e|"; }
            , "s1"_s + event<ev1> / [this](sml::back::process<ev2, ev3> p) -> void {
                calls += "a1.begin|";
                std::thread t([&](auto&& processEvent)
                {
                    std::cout << "Pew!" << std::endl;
                    processEvent(ev2{});
                    std::this_thread::sleep_for(std::chrono::seconds(1));
                    std::cout << "Pew pew!" << std::endl;
                    processEvent(ev3{});
                }, p);
                t.detach();
                calls += "a1.end|";
            }
            , "s1"_s + event<ev2> / [this] { calls += "a2|"; }
            , "s2"_s + event<ev3> / [this] { calls += "a3|"; }
            , "s1"_s + unexpected_event<ev3> / [this] { calls += "err|"; } = X
        );
        // clang-format on
    }

    std::string calls{};
};

Godbolt: https://godbolt.org/z/5rG8E99o7

Sadly, when I run it, I get this:

[c][process_event] boost::sml::back::on_entry<boost::sml::back::_, boost::sml::back::initial>
[c][action] (lambda at /app/example.cpp:50:49) boost::sml::back::on_entry<boost::sml::back::_, boost::sml::back::initial>
[c][process_event] ev1
[c][action] (lambda at /app/example.cpp:51:37) ev1
Pew!
Pew pew!
s1e|a1.begin|a1.end|

Neither ev2 nor ev3 get processed by the state machine. Any idea how I can get this working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant