|
Boost : |
Subject: Re: [boost] Any interest in a M:N green threading library?
From: Chen Xu (windoze.net_at_[hidden])
Date: 2015-08-12 23:39:45
Yes, green thread is some kind of wrapper of a ASIO strand.
The point is, Boost.Asio and Boost.Coroutine strand do not have any
synchronization mechanism.
For example, a web server uses MySQL, in order to use database
connection pool, you need to pause a strand when no spare DB connection
available, and resume it when some other strand release a connection, a
lot of code needed to do it correctly and you cannot just block worker
thread as this will decrease performance significantly.
By wrapping all these codes into standard compliant synchronization
primitives, you can write program just like you are using normal
threads, except they are scheduled by green_thread/io_service, no
native worker threads get blocked when a green thread is waiting on
things like mutex.
Rust used to support green thread, showed how it can simplify server
side programming. Also there is another project, Vibe.d written in D
(http://vibed.org), has same design.
Regards,
Chen Xu
On 2015-08-12 23:47:08 +0000, Gavin Lambert said:
> On 13/08/2015 04:58, Chen Xu wrote:
>> 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.
>
> Can you explain how this is different from giving a single Boost.Asio
> io_service multiple worker threads, and just queuing work/operations to
> the io_service (possibly via strands)?
>
> The description above makes it sound like a "green thread" is identical
> to a strand.
>
>
>
> _______________________________________________
> 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