Boost logo

Boost :

From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2023-10-11 17:11:37


On 11/10/2023 17:57, Richard Hodges via Boost wrote:

> I must claim some culpability for this. I was an early adopter of the
> library, which itself is a distant descendant of work I and later Klemens
> did to replicate Go's channel and select() in C++ I/O loops.
>
> The Go select() function does exactly what Klemens' does - suspends until
> the first source/coroutine has a value available (ties broken by pseudo
> random selection in order to prevent starvation of the right-most sources),
> and then continues, leaving the values in the unselected coroutines
> available for subsequent select() calls.
>
> Being a user of Asio for the past decade, It didn't occur to me that people
> still actually used BSD select()...
>
> Accepting that the name select() is not acceptable, my motivation for
> encouraging Klemens to have the default xxx() function take a random ready
> value, and the left_xxx() function to take the leftmost, was that taking
> the leftmost ready value is very likely to lead to starvation of code that
> responds to the the right-most sources delivering values if the leftmost
> sources are constantly ready. xxx() is therefore the safer unsurprising
> default for an inexperienced or tired developer.

If I were designing that API, I'd personally provide a user supplied
callable which gets invoked to decide on the tie break, and I'd default
its implementation to one choosing randomly. Then users can choose
whatever suits them, and no need for left_xxx() functions etc.

Niall


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