Go /
Goroutine-localStorageРазные (или одинаковые - не знаю) реализации: https://github.com/modern-go/gls -> https://github.com/huandu/go-tls https://github.com/jtolds/gls - есть проблемы с производительностью (см. issues). Как более хорошую альтернативу советуют https://github.com/tylerb/gls Реализация на ассемблере: https://github.com/cosmos72/gls Как сделать локальное хранение ещё лучше? SO: https://stackoverflow.com/questions/26344750/how-to-identify-a-goroutine Обсуждение: https://groups.google.com/forum/#!topic/golang-nuts/Nt0hVV_nqHE Вот кусок кода из этого обсуждения, якобы переносимый: import ( "fmt" "runtime" "strconv" "strings" "sync" ) func goid() int { var buf [64]byte n := runtime.Stack(buf[:], false) idField := strings.Fields(strings.TrimPrefix(string(buf[:n]), "goroutine "))[0] id, err := strconv.Atoi(idField) if err != nil { panic(fmt.Sprintf("cannot get goroutine id: %v", err)) } return id } func main() { fmt.Println("main", goid()) var wg sync.WaitGroup for i := 0; i < 10; i++ { i := i wg.Add(1) go func() { defer wg.Done() fmt.Println(i, goid()) }() } wg.Wait() } |