воскресенье, 22 сентября 2024 г.

Fibers

https://habr.com/ru/companies/piter/articles/491996/

#define NOMINMAX

#include <cstdlib>
#include <iostream>z
#include <memory>
#include <string>
#include <thread>

#include <boost/intrusive_ptr.hpp>

#include <boost/fiber/all.hpp>

inline
void fn( std::string const& str, int n) {
for ( int i = 0; i < n; ++i) {
std::cout << i << ": " << str << std::endl;
boost::this_fiber::yield();
}
}

int main() {
try {
boost::fibers::fiber f1( fn, "abc", 5);
std::cerr << "f1 : " << f1.get_id() << std::endl;
f1.join();
std::cout << "done." << std::endl;

return EXIT_SUCCESS;
} catch ( std::exception const& e) {
std::cerr << "exception: " << e.what() << std::endl;
} catch (...) {
std::cerr << "unhandled exception" << std::endl;
}
return EXIT_FAILURE;
}

Комментариев нет:

Отправить комментарий

Boost, Asio, Github

Boost, Asio, Github https://github.com/ru-cpp-tutorials/asio-tutorial/ https://github.com/freeacetone/BoostAsioBookRussian