Skip to content

Instantly share code, notes, and snippets.

Overview

This is a minimal example that shows the 4 main building-blocks needed to write concurrent/async coroutine code.

  1. A coroutine type that lets users write their coroutine logic and call and co_await other coroutines that they write. This allows composition of async coroutine code.

This example defines a basic task type that fulfills this purpose.

@lewissbaker
lewissbaker / async_coroutine_example.cpp
Created May 24, 2022 03:58
Implementation of minimal set of components for writing concurrent async coroutine code in C++20.
/////////////////////////////////////////////////////////////////////////
// This is a minimal example that shows the 4 main building-blocks needed to
// write concurrent/async coroutine code.
//
// 1. A coroutine type that lets users write their coroutine logic
// and call and co_await other coroutines that they write.
// This allows composition of async coroutine code.
//
// This example defines a basic `task<T>` type that fulfills this purpose.
//
ssize_t getAsyncStackTraceSafe(uintptr_t* addresses, size_t maxAddresses) {
size_t numFrames = 0;
// Start by walking the normal stack until we get to the frame right before
// the frame that holds the async root.
StackFrame* normalStackFrame = (StackFrame*)FOLLY_ASYNC_STACK_FRAME_POINTER();
StackFrame* normalStackFrameStop = nullptr;
const auto* asyncStackRoot = tryGetCurrentAsyncStackRoot();
AsyncStackFrame* asyncStackFrame = nullptr;
@lewissbaker
lewissbaker / executor_compromise.md
Last active September 7, 2018 19:52 — forked from LeeHowes/executor_compromise.md
P1055 and P0443 - a compromise

P1055 and P0443 - a compromise

Summary

The goal here is to provide a minimal set of changes to P0443 that allows us to aim for a clean, lazy-by-default API, that does not drastically change the expectations of the P0443 authors.

I am making a few assumptions in writing this:

  • I am not worrying about bikeshedding names. Where appropriate I will use names from P0443 even if they don't really make sense any more as names. We can change them.
  • I believe we may wish to tweak the particular parameters to the bulk execute operation. We will likely also want other types of task such as a value + error task as I described in P1054. I do not worry about that here.
  • I do not expect changes to the properties mechanism except in so much as the types they return may differ slightly.