Skip to content

Instantly share code, notes, and snippets.

View markpapadakis's full-sized avatar
💭
Seeking Knowledge 24x7

Mark Papadakis markpapadakis

💭
Seeking Knowledge 24x7
View GitHub Profile
@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.
//
__attribute__((noreturn)) void unreachable()
{
__builtin_unreachable();
}
#define assume(x) if (x) ; else unreachable()
// Placement new without the null pointer check
template<class T, class... Args>
void construct(T* p, Args&&... args)