Via C++ Next, hat tip to Dave Abrahams:
Chris Kohlhoff’s ASIO library contains an extraordinary little header, not in the public interface, but in the examples directory, that implements what he calls “Stackless Coroutines” (very similar to Python’s Simple Generators if you’re familiar with those). He does it completely portably, with just a few macros, and considering that there are zero lines of platform-specific code, they work amazingly well.
Dave cites this article that describes how to use the coroutines:
A potted guide to stackless coroutines
Keen-eyed Asio users may have noticed that Boost 1.42 includes a new example, HTTP Server 4, that shows how to use stackless coroutines in conjunction with asynchronous operations. This follows on from the coroutines I explored in the previous three posts, but with a few improvements. In particular:
- the pesky entry pseudo-keyword is gone; and
- a new fork pseudo-keyword has been added.
The result bears a passing resemblance to C#'s yield and friends. This post aims to document my stackless coroutine API, but before launching into a long and wordy explanation, here's a little picture to liven things up...
Add a Comment
Comments are closed.