Created
February 11, 2022 08:44
-
-
Save PratikDeoghare/1f3f2f021e8f840af9ee4a73527efe1c to your computer and use it in GitHub Desktop.
Revisions
-
PratikDeoghare created this gist
Feb 11, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ package main import ( "fmt" "sync" "time" ) func main() { newPort := func() func() int { x := 4000 var mu sync.Mutex return func() int { mu.Lock() x++ y := x mu.Unlock() return y } }() _ = newPort localPort := make(chan uint16) go func() { for i := 5000; i < 60000; i++ { localPort <- uint16(i) } }() var m sync.Map for i := 0; i < 10000; i++ { go func() { //p := newPort() p := <-localPort _, ok := m.Load(p) if ok { panic(p) } else { m.Store(p, 1) } fmt.Println(p) }() } time.Sleep(time.Second * 10) }