Under the assumption that the range-over-function proposal is accepted and that the following code:
for x := range seq(3) {
	fmt.Println(x)
}
compiles equivalently to:
seq(3)(func(x int) bool {
fmt.Println(x)
| var Builtins = []*Function{ | |
| ... | |
| { | |
| Name: "first", | |
| Fast: Len, | |
| Func: initializeBuiltins("first"), | |
| ... | |
| } | |
| ... | |
| } | 
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn <- + | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn <- $QStartNoAckMode#b0 | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn -> + | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn -> $OK#9a | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn <- + | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn <- $QThreadSuffixSupported#e4 | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn -> $OK#9a | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn <- $qSupported:swbreak+;hwbreak+;no-resumed+;xmlRegisters=i386#c5 | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn -> $PacketSize=1048576;QStartNoAckMode+;qXfer:features:read+;qXfer:auxv:read+;qXfer:exec-file:read+;qXfer:siginfo:read+;qXf... | |
| 2024-07-09T15:15:45+02:00 debug layer=gdbconn <- $qRegisterInfo0#72 | 
Under the assumption that the range-over-function proposal is accepted and that the following code:
for x := range seq(3) {
	fmt.Println(x)
}
compiles equivalently to:
seq(3)(func(x int) bool {
fmt.Println(x)
| package main | |
| import ( | |
| "fmt" | |
| "reflect" | |
| ) | |
| type Bstruct struct { | |
| n float64 | |
| } | 
| #include <stdio.h> | |
| #include <pthread.h> | |
| int N = 100000; | |
| //int N = 20; | |
| pthread_mutex_t ping_lock = PTHREAD_MUTEX_INITIALIZER, pong_lock = PTHREAD_MUTEX_INITIALIZER; | |
| pthread_cond_t ping_cond, pong_cond; | |
| pthread_t ping_thread, pong_thread; | |
| int can_ping = 1, can_pong = 0; | 
| package main | |
| import ( | |
| "runtime" | |
| "runtime/pprof" | |
| _ "runtime/trace" | |
| "fmt" | |
| "time" | |
| "os" | |
| ) | 
| append.go:29 0x454e8d main._Append | |
| append.go:29 0x454e95 main._Append | |
| append.go:29 0x4550ad main._Append | |
| append.go:29 0x4550b5 main._Append | |
| chans.go:412 0x48c4e2 main.TestReadAll | |
| chans.go:412 0x48c4e4 main.TestReadAll | |
| chans.go:412 0x48c7c9 main.TestMerge | |
| chans.go:412 0x48c7ce main.TestMerge | |
| chans.go:412 0x48c912 main.TestMerge | |
| chans.go:412 0x48c914 main.TestMerge | 
The aim of this proposal is to extend the LockOSThread mechanism so that it is possible to create a N:1 association between N goroutines and 1 OS thread, by adding the following function to the runtime package
func LockToRecvOSThread[T any](ch <- chan T)
When LockToRecvOSThread is called the calling goroutine will be locked to the same thread as the goroutine receiving on ch, which is assumed to be already locked to a OS thread.
| package main | |
| import ( | |
| "bufio" | |
| "bytes" | |
| "encoding/json" | |
| "fmt" | |
| "io" | |
| "io/ioutil" | |
| "net/http" | 
| // This requires tip of Go master branch for 1.18; `gotip` is a great tool to | |
| // use. | |
| // | |
| // Run benchmark with | |
| // $ gotip test -bench=. <filename> | |
| package main | |
| import ( | |
| "math/rand" |