>> If several different goroutines decide to wake up the polling
>> goroutine before the polling goroutine wakes up, they will each write
>> a single byte

Wondering, with the introduction of "netpollWakeSig", does it still hold 
true? Thanks.

On Tuesday, July 11, 2023 at 9:00:36 AM UTC+8 Ian Lance Taylor wrote:

> On Mon, Jul 10, 2023 at 6:10 AM shaouai <aou...@gmail.com> wrote:
> >
> > In the implementation of the Go netpoller, `netpollBreak()` attempts to 
> write 1 byte to `netpollBreakWr`, whereas `netpoll()` reads up to 16 bytes 
> from `netpollBreakRd`, why 16 bytes rather than 1 byte?
> >
> > write up to 1 byte: 
> https://cs.opensource.google/go/go/+/refs/tags/go1.20.5:src/runtime/netpoll_epoll.go;l=77;drc=c7cc2b94c63af610a29b1b48cfbfb87cb8abf05b
> >
> > read up to 16 bytes: 
> https://cs.opensource.google/go/go/+/refs/tags/go1.20.5:src/runtime/netpoll_epoll.go;l=146;drc=c7cc2b94c63af610a29b1b48cfbfb87cb8abf05b
>
> A single byte will wake up a goroutine sleeping in netpoll, so there
> is no reason to write more than one byte.
>
> If several different goroutines decide to wake up the polling
> goroutine before the polling goroutine wakes up, they will each write
> a single byte, and they will all be satisfied by a single wakeup.
> And, if we don't read all those bytes, there will still be bytes in
> the pipe and we'll wake up the next time around the poll loop even if
> we don't have to. So we try to read all of their wakeup bytes at
> once. The number 16 is arbitrary, based on the assumption that it's
> not all that likely that more than 16 goroutines will try to wake up
> the poller simultaneously.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8a3ae80e-1e78-441d-8c9a-c99e94e3c2c9n%40googlegroups.com.

Reply via email to