Re: [go-nuts] Interesting "select" examples

2023-04-07 Thread Andrew Harris
I was surprised looking through old code that I didn't have much in the way of "interesting, non-trivial" selects - in every case where I remember doing something interesting through a select statement, later versions had moved to less interesting selects, more interesting messages from

Re: [go-nuts] Interesting "select" examples

2023-04-07 Thread Bakul Shah
> On Apr 4, 2023, at 6:20 AM, Jesper Louis Andersen > wrote: > > On Tue, Apr 4, 2023 at 2:22 AM Nigel Tao > wrote: >> >> I'd have to study mux9p for longer, but its select chooses between two >> receives, so it could possibly collapse to a single heterogenous >>

Re: [go-nuts] Interesting "select" examples

2023-04-06 Thread 'Dan Kortschak' via golang-nuts
On Mon, 2023-04-03 at 14:59 -0700, Skip Tavakkolian wrote: > Nice pause/resume. I'll need to remember this. > > On Mon, Apr 3, 2023 at 3:14 AM Rob Pike wrote: > > > > Here's an excerpt from a piece of concurrent code I like, an > > unpublished interactive game of life. The select near the bottom

Re: [go-nuts] Interesting "select" examples

2023-04-04 Thread Jesper Louis Andersen
On Tue, Apr 4, 2023 at 2:22 AM Nigel Tao wrote: > > I'd have to study mux9p for longer, but its select chooses between two > receives, so it could possibly collapse to a single heterogenous > channel. Indeed, both its channels are already heterogenous in some > sense. Both its processTx and

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Robert Engels
Interesting - that page has “ Thread stacks are allocated in shared memory, making it valid to pass pointers to stack variables between threads and procs.” That seems very difficult to pull off safely. > On Apr 3, 2023, at 9:46 PM, Skip Tavakkolian > wrote: > > On Mon, Apr 3, 2023 at 5:22 

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Skip Tavakkolian
On Mon, Apr 3, 2023 at 5:22 PM Nigel Tao wrote: > > On Tue, Apr 4, 2023 at 7:56 AM Skip Tavakkolian > wrote: > > mux9p, Fazlul Shahriar's port of Russ' 9pserve (plan9port) > > https://github.com/fhs/mux9p/search?q=clientIO > > > > ... > > > > select { > > case v, ok := <- counts: > >

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Robert Engels
Nothing concrete but I envision a system where the super set is all the request channels - when a request is received a routine is spawned/called with the related request response and status channels - a subset of all channels. Contrived but just thinking out loud. > On Apr 3, 2023, at 8:28

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Robert Engels
Tbh I’m not sure but I am uncertain how you would get a system with 1000+ independent channels coalesced into a single channel - seems that would become highly contended/bottleneck. More importantly, I think the processing often involves subsequent stages operating on a subset of the original

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Nigel Tao
On Tue, Apr 4, 2023 at 8:06 AM Ian Lance Taylor wrote: > Some of the select statements in net/http/transport.go are non-trivial. Yeah, net/http (and its transport.go) is probably equally good an example of selects as golang.org/x/net/http2 (and its transport.go). But that's not really

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Nigel Tao
On Tue, Apr 4, 2023 at 7:56 AM Skip Tavakkolian wrote: > mux9p, Fazlul Shahriar's port of Russ' 9pserve (plan9port) > https://github.com/fhs/mux9p/search?q=clientIO > > ... > > select { > case v, ok := <- counts: > // collect samples > case reporting <- Stats{ stats }: >

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Robert Engels
I think it is as simple as looking at kselect/poll in posix. Each descriptor can be viewed as an independent channel of info/objects. Select with Go channels works similarly and has similar usefulness. > On Apr 3, 2023, at 7:00 PM, Nigel Tao wrote: > > On Mon, Apr 3, 2023 at 8:14 PM Rob

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Nigel Tao
On Mon, Apr 3, 2023 at 8:14 PM Rob Pike wrote: > select { > case <-ticker.C: > case <-pauseC: > <-pauseC > } This one is more interesting. You can't combine the ticker.C and the pauseC into a single heterogenous channel because you want to wait for the

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Nigel Tao
On Mon, Apr 3, 2023 at 3:40 PM Konstantin Kulikov wrote: > select { > case <-ctx.Done(): > case linksCh <- links: > } On Tue, Apr 4, 2023 at 1:15 AM burak serdar wrote: > select { > case <-pause: > case <-done: > return > } Thanks, but I think both

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Ian Lance Taylor
On Sun, Apr 2, 2023 at 8:44 PM Nigel Tao wrote: > > Does anyone have interesting, non-trivial examples of a Go select > statement in real code? Some of the select statements in net/http/transport.go are non-trivial. Ian -- You received this message because you are subscribed to the Google

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Skip Tavakkolian
Nice pause/resume. I'll need to remember this. On Mon, Apr 3, 2023 at 3:14 AM Rob Pike wrote: > > Here's an excerpt from a piece of concurrent code I like, an unpublished > interactive game of life. The select near the bottom has only two cases but > it is perhaps instructive. I leave its

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Skip Tavakkolian
I think this qualifies: mux9p, Fazlul Shahriar's port of Russ' 9pserve (plan9port) https://github.com/fhs/mux9p/search?q=clientIO I've used this dispatcher pattern: func dispatcher(commands chan Cmd, reporting chan Stats, worker Worker) { control = make(chan ...) counts = make(chan ...)

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread burak serdar
Below is part of a generic ordered fan-in for data pipelines. It works by reading data from multiple channels using one goroutine for each channel, sending that data element to another goroutine that does the actual ordering, but in the mean time, pauses the pipeline stage until all out-of-order

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread Rob Pike
Here's an excerpt from a piece of concurrent code I like, an unpublished interactive game of life. The select near the bottom has only two cases but it is perhaps instructive. I leave its analysis to the reader. -rob var kbdC chan of rune = ... // events from keyboard var ticker =

Re: [go-nuts] Interesting "select" examples

2023-04-02 Thread Konstantin Kulikov
Below is an example of code that does some work even after timeout. In a perfect world it would be simple "return FetchLinks(user)", but unfortunately 3rd-party service is unreliable, so we did some caching and timeouts. The idea is as follows: User sends a request, we try to fetch data from a

[go-nuts] Interesting "select" examples

2023-04-02 Thread Nigel Tao
I'm working on a multi-threaded C++ project. We have the equivalent of Go's channels, and are considering whether we also need to implement the equivalent of Go's select. Does anyone have interesting, non-trivial examples of a Go select statement in real code? By non-trivial, I mean that a lot