企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ package main import ( "fmt" "sync" "time" ) func main() { const numGoroutines = 100 const iterations = 100000 var data int var mu sync.Mutex var wg sync.WaitGroup startTime := time.Now() for i := 0; i < numGoroutines; i++ { wg.Add(1) go func() { for j := 0; j < iterations; j++ { mu.Lock() data++ mu.Unlock() } wg.Done() }() } wg.Wait() endTime := time.Now() elapsedTime := endTime.Sub(startTime) fmt.Println("Final data value:", data) fmt.Println("Total time taken:", elapsedTime) } ~~~