Boost logo

Boost :

From: Richard Hodges (hodges.r_at_[hidden])
Date: 2023-10-11 18:02:56


Sent from my iPad

> On 11 Oct 2023, at 21:11, Niall Douglas via Boost <boost_at_[hidden]> wrote:
>
> 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.

This is probably why it’s best I stick to hacking together trading systems.

Wouldn’t it be difficult to default the argument to prefer_left() or similar though, given that the parameters are a variadic pack of sources?

Not having a default would be unacceptable to me as it would involve:
- more typing, and
- having to read the documentation prior to hacking the code together.

>
> Niall
>
> _______________________________________________
> 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