Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
boost::asio strands and coroutines: How to move into and out of a strand?
Post Flair (click to view more posts with a particular flair)
Post Body

So I have a coroutine I've spawned via asio::spawn that's handling an HTTP connection.

I have a shared object with a bunch of variables that I want to use from various HTTP handlers. To that end, I have a strand to serialize access to these variables.

I know I can asio::spawn(<strand>, <handler>) initially, but I don't want to hog the strand for the whole HTTP connection.

Is there a way I can suspend/awaken my coroutine inside a strand, and then suspense/awaken back outside when I'm done?

Initially I was just using asio::spawn(<strand>, <handler>) to execute operations on my shared object because I don't strictly need to wait for things to finish, but I'm anticipating issues where coroutines pile up and cause resource exhaustion. In other words, I'm trying to implement some back pressure (HTTP requests don't complete until the operation is complete).

Any ideas? This seems like it should be really easy. I remember using async/await in C# and "teleporting" between different contexts (e.g. getting onto the main thread then back into a worker pool) was fairly trivial.

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
5,214
Link Karma
323
Comment Karma
4,871
Profile updated: 5 days ago
Posts updated: 3 days ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago