Boost logo

Boost :

Subject: Re: [boost] Any interest in a M:N green threading library?
From: Chen Xu (windoze.net_at_[hidden])
Date: 2015-08-12 12:58:06


These 2 libs look similiar, but there are some big differences.

boost-fiber uses M:1 scheduling, it uses a single threaded scheduler to
run multiple fibers within one thread.
Pros:
        Most synchronizations between native threads can be avoided as it's
single threaded.
        You can use native TLS in fibers, which is more efficient than the
implementations in Boost.Thread and boost.green_thread.
Cons:
        Although you can create multiple threads to run multiple sets of
fibers, each set of fibers are seperated, you need additional efforts
to migrate a fiber from a thread to another(work-stealing), also TLS
needs to be avoided in this case.
        Even with work stealing enabled, multiple fiber groups are often run
into imbalance, because work stealing is not automatic in boost-fiber.

boost.green_thread uses M:N scheduling, it schedules a group of green
threads across multiple native threads.
Pros:
        boost.green_thread uses ASIO io_service for scheduling, seamlessly
cooperate with ASIO.
        Load is balanced across all native threads in a scheduler, server side
programs can utilize multi CPU cores more efficiently.
Cons:
        Multiple native worker threads need synchronization to schedule green threads
        Scheduling is more complex than boost-fiber, makes a scheduler with
only one worker thread runs slightly slower than boost-fiber.
        Cannot use native TLS as green threads may migrate between native threads.

Both libraries have their own pros and cons, and fit in different
scenarios, my opinion, boost.green_thread is better for server side
programs as it can utilize multi cores easily.

Regards,
Chen Xu

On 2015-08-12 15:08:23 +0000, Klaim - Joël Lamotte said:

> On 12 August 2015 at 16:20, Xu Chen <windoze.net_at_[hidden]> wrote:
>
>> Just cleanup some codes I wrote before, there is a M:N green threading
>> library built on top of Boost.Thread and Boost.Coroutine, conceptually it
>> works like goroutines in Go and (once existed) green threads in Rust.
>>
>> With some refinements, it now supports all C++11/14 threading standard,
>> along with some extensions exist in Boost.Thread such as thread_group and
>> chainable futures.
>>
>> It can be integrated with Boost.ASIO, all ASIO async functions can be used
>> as sync ones in green threads, similar to Boost.ASIO/Boost.Coroutine
>> integration.
>>
>> Also it has some facilities to communicate with foreign threads, can by
>> used to integrate with external libs such as database drivers.
>>
>> The code can be found at https://github.com/windoze/boost.green_thread
>>
>> I don't know much about boostbook tools so the documents are kind of
>> crippled, but I'll improve it if needed.
>>
>> Regards,
>> Chen Xu
>>
>>
> I am not an expert in the domain but am I correct that you are proposing
> similar
> functionality to Boost.Fiber? ( https://github.com/olk/boost-fiber )
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk