package main import ( "fmt" "sync" "time" ) var ( m = make(map[int]uint64) lock sync.Mutex ) type task struct { n int } func calc(t *task) { var sum uint64 sum = 1 for i := 1; i <= t.n; i++ { sum *= uint64(i) } lock.Lock() m[t.n] = sum lock.Unlock() } func main() { for i := 0; i < 10; i++ { t := &task{n:i} go calc(t) } time.Sleep(1 * time.Second) lock.Lock() for k, v := range m { fmt.Printf("%d! = %v\n", k, v) } }
Read More:
- Flutter & Dart Regular Expression Examples
- How to Use Printf in HAL Library
- Windows Core Audio APIs: How to Progress Loopback Recording and Generate WAV File
- Android: How to Add Background Music for Activity with Service
- Echarts-for-React Example (Install, Import and Effect)
- Python: How to Create List by Comprehension (Example Codes)
- Jquery use queue to implement Ajax request queue Simple Example
- Opentelemetry + Jaeger Python Version Cross Service Call Example
- Flutter & Dart Enumeration Example
- Matplotlib Draw 3D scatter Diagram Example
- Docker: How to build a rabbitmq image cluster
- MAFIA: 1- OpenFlow statistics (Counters, Timestamps)(mafia-sdn/p4demos/demos/1-openflow/1.1-statistics/p4src/of.p4)
- Flutter & Dart every() Method Example
- WCNSS_qcom_cfg.ini WIFI Configuration File Guide
- Hutool Excel Import & Export Example
- File class details (get the file name, size, path, create, etc.)
- torch.max Example (How to Use)
- Electron: How to Use BrowserWindow to Create a Window
- Websocket Front-end Call Example