I'm only sitting here, waiting for my thread_locals to get broken.... or maybe they are handled magically somehow
Stackful vs stackless comes with a few pro's and con's - e.g. it's often argued that stackless requires less memory. However stackful coroutines can allow for preemption at arbitrary points instead of just at yield points.
Stackful coroutines didn't require any compiler support, unlike stackless so they've be available for a long time (stackless have also been around since C++20).
e.g. if you have this code with boost:
#include <boost/asio.hpp>
#include <chrono>
#include <vector>
#include <thread>
#include <iostream>
std::mutex print_mutex;
int main()
{
using namespace boost::asio;
using namespace std::literals;
io_context io_context(20);
auto work_guard = make_work_guard(io_context);
for(int i = 0; i < 100; i++) {
post(io_context, [&] {
thread_local int x = 0;
int z = x++;
std::lock_guard _{print_mutex};
std::cout << z << "\n";
});
}
std::vector<std::jthread> v;
for(int i = 0; i < 20; i++)
v.emplace_back([&] { io_context.run_for(2s); });
}
i hope you don't expect the output to be "0, 1, 2, ..., 99"