协程、协程2和光纤有什么区别

What is the difference between Coroutine, Coroutine2 and Fiber?

本文关键字:协程 什么 区别 光纤      更新时间:2023-10-16

Boost 中有 3 个具有手动低延迟上下文切换的细线程:

  • Boost.Coroutine: http://www.boost.org/doc/libs/1_64_0/libs/coroutine/doc/html/index.html
  • Boost.Coroutine2: http://www.boost.org/doc/libs/1_64_0/libs/coroutine2/doc/html/index.html
  • 增强纤维:http://www.boost.org/doc/libs/1_64_0/libs/fiber/doc/html/index.html

协同程序 1、协同程序 2 和 Fiber in Boost 有什么区别?

boost.coroutine是非C++11,因此需要使用boost.context中的私有API(因为它已被弃用(。

boost.coroutine2boost.fiber 需要 C++11 并使用 Boost.context 中的 callcc((/continuation (实现上下文切换、当前延续调用(。

boost.coroutine和boost.coroutine2实现了

coroutines,而boost.fiber则提供类似于std:thread的API的fibers(== lightweigt,coroperative userland-threads,green-threads等(。

N4024:区分协程和纤程中描述了协程和纤程之间的区别 - 简而言之:纤程由内部调度程序切换,而协程不使用内部调度程序