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

async_mutex, lock in a task, and unlock in the other task, the assert != not_locked failed? #224

Closed
bbqz007 opened this issue Dec 24, 2024 · 1 comment

Comments

@bbqz007
Copy link

bbqz007 commented Dec 24, 2024

async_mutex mtx;
tsk_lock=
[&](){
 assert(mtx.try_lock());
 co_return;
}

tsk_unlock=
[&](){
 mtx.unlock();  /// failed assert != not_locked
 co_return;
}

when_all(tsk_lock(), tsk_unlock());
@bbqz007
Copy link
Author

bbqz007 commented Dec 26, 2024

it is the problem there is some task without co_return;

                   auto tsk_lock = [&]()->cppcoro::task<>{
                        mtx.try_lock();
                        // co_return;       ///  without it, it makes things unexpected. it makes my unlock() in next task failed assert != not_locked
                    };
                    auto tsk_mtx = [&](int i)->cppcoro::task<>{
                        co_await A(i);
                        co_await mtx.lock_async();
                        co_await Aa(i);
                        co_await pool.schedule();
                        co_await C(i);
                        mtx.unlock();
                        co_await D(i);
                        co_return;
                    };
                    auto tsk_unlock = [&]()->cppcoro::task<>{
                        mtx.unlock();
                        // co_return;
                    };
                   cppcoro::when_all(tsk_lock(), tsk_mtx(1), tsk_mtx(2), tsk_mtx(3), tsk_unlock());

@bbqz007 bbqz007 closed this as completed Dec 26, 2024
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