this post was submitted on 06 Jul 2023
13 points (100.0% liked)
C++
1786 readers
2 users here now
The center for all discussion and news regarding C++.
Rules
- Respect instance rules.
- Don't be a jerk.
- Please keep all posts related to C++.
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
A few points:
std::scoped_lock
overstd::lock_guard
.std::mutex
, not a map (ie in its constructor)foo
is called a completion handler; one way to thread a bunch of (related) handlers without needing explicit locks is to use so-called strands. As long as all the operations which have to be performed serially are coroutines, spawned within strand in question, you can actually have a thread pool of executors running, and asio will take care of all the locking complexity for you.p
in the block as a whole, and within the completion handler, so be aware that thep
outside has to be well-defined, and that the interior one (in the lambda) shadows the outer one. (I'm a fan of shadowing, btw, the company I used to have lint settings which yelled when shadowing happens, but for me it's one of the features I want, because it leads to more concise, uniform, clear names -- and that in turn is because shadowing allows them to be reused, but in the specific context... anyyyyway)foo
, you makefoo
an awaitable functor whichco_yields
an index (p
, above), one which we canco_await
as in:boost::asio
, then you get access to all this.