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

calling set() to cppcoro::async_manual_reset_event in coroutine, throw broken promise #223

Closed
bbqz007 opened this issue Dec 24, 2024 · 2 comments

Comments

@bbqz007
Copy link

bbqz007 commented Dec 24, 2024

cppcoro::async_mutex mtx;
                cppcoro::async_manual_reset_event event;
                auto tsk = [&]()->cppcoro::task<>{

                    auto tsk_lock = [&]()->cppcoro::task<>{
                        cppcoro::async_mutex_lock lck = co_await mtx.scoped_lock_async();
                        co_await event;           
                         };
/// terminate called after throwing an instance of 'cppcoro::broken_promise'what():  broken promise
                    auto tsk_unlock = [&]()->cppcoro::task<>{
                        event.set();
                    };
                    co_await cppcoro::when_all(tsk_lock(), tsk_unlock());
@bbqz007 bbqz007 changed the title co_await under async_mutex protection, broken promise when unlock(). calling set() to cppcoro::async_manual_reset_event in coroutine, throw broken promise Dec 24, 2024
@bbqz007
Copy link
Author

bbqz007 commented Dec 26, 2024

the problem is that
there is no co_return in a the coro code.
the compiler did not make error even though i did not write the co_return.
in most cases, if my coro code ends with co_await, the code even run ok.
that make me have a wrong idea that there is not need a co_return; if task。

@bbqz007 bbqz007 closed this as completed Dec 26, 2024
@bbqz007
Copy link
Author

bbqz007 commented Dec 26, 2024

yes, all the coro task need the co_return;

                    auto tsk_lock = [&]()->cppcoro::task<>{
                        co_return;      /// co_return is needed, if not, it return some thing unexpected.
                    };
                    auto tsk_unlock = [&]()->cppcoro::task<>{
                        event.set();
                        co_return;
                    };
                    auto tsk_ev = [&](int i)->cppcoro::task<>{
                        co_await A(i);
                        co_await event;
                        co_await Aa(i);
                        co_await D(i);
                       // co_return;           /// without this, it crash the set() and resume() too.
                    };
                    co_await cppcoro::when_all(tsk_lock(), tsk_ev(1), tsk_ev(2), tsk_ev(3), tsk_unlock());
                };

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