3 ms·
I mean, for sure but that's not a property of coroutines, any callback system can do that e.g. if you have this code with boost: #include <boost/asio.hpp>
by jcelerier 4y ago
I mean, for sure but that's not a property of coroutines, any callback system can do that
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"
- deleted 4y ago[deleted]