💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ 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) } ~~~