ရိုးရိုးလေး ရှင်းပြမယ်
Synchronization ကို ရိုးရိုးလေး ပြောရရင်
Goroutine တွေက အလုပ်တွေကို တပြိုင်နက် လုပ်ပေးနိုင်ပါတယ်။ ပြဿနာက သူတို့ အားလုံး variable တစ်ခုတည်းကို ဖတ်ပြီး ပြင်ကြတဲ့အခါ စတင်ပါတယ်။ Goroutine နှစ်ခုက တန်ဖိုးဟောင်းကို တစ်ချိန်တည်း ဖတ်ပြီး တစ်ခုစီ တိုးရေးလိုက်ရင် update တစ်ခု ပျောက်သွားပါတယ်။ ဒါကို data race လို့ ခေါ်ပါတယ်။
အိမ်သာ တံခါးသော့ကို စဉ်းစားကြည့်ပါ။ အထဲမှာ တစ်ယောက်ပဲ ဝင်ခွင့်ရှိပြီး ကျန်တဲ့သူတွေက သော့ ပြန်ချပေးတဲ့အထိ စောင့်ရပါတယ်။ sync.Mutex က အဲဒီ သော့ပါပဲ။ Shared data ကို ထိမယ့် code အပိုင်းကို Lock နဲ့ Unlock ကြားမှာ ထားလိုက်ရင် တစ်ကြိမ်မှာ goroutine တစ်ခုပဲ ဝင်နိုင်ပါတယ်။
Problem → Why → Solution
ပြဿနာ: တစ်ခါတလေမှ မှားတဲ့ counter
Website တစ်ခုရဲ့ request အရေအတွက်ကို ရေတွက်ချင်တယ် ဆိုပါစို့။ Request တစ်ခုစီက goroutine တစ်ခုစီမှာ run ပြီး shared counter ကို counter++ နဲ့ တိုးပါတယ်။ သင့် laptop ပေါ်မှာ စမ်းကြည့်တော့ 1000 ထွက်ပါတယ်၊ နောက်တစ်ခါ run တော့ 987၊ CI server ပေါ်မှာတော့ 941 ထွက်ပါတယ်။ Compile error မရှိ၊ panic မရှိ၊ အမှားက လုံးဝ တိတ်ဆိတ်နေပါတယ်။
package main
import (
"fmt"
"sync"
)
func main() {
counter := 0
var wg sync.WaitGroup
for range 1000 {
wg.Add(1)
go func() {
defer wg.Done()
counter++ // DATA RACE: read, add, write are three separate steps
}()
}
wg.Wait()
fmt.Println(counter) // often less than 1000
}counter++ က ဘာကြောင့် လုံခြုံမှု မရှိတာလဲ
counter++ က တစ်ကြောင်းတည်း ဖြစ်ပေမဲ့ CPU အတွက်တော့ အဆင့်သုံးဆင့်ပါ: memory ကနေ ဖတ်၊ 1 ပေါင်း၊ ပြန်ရေး။ Goroutine နှစ်ခုက 41 ကို တစ်ချိန်တည်း ဖတ်မိရင် နှစ်ခုလုံး 42 ကို ရေးပြီး increment တစ်ခု ပျောက်ပါတယ်။ ဒါ့အပြင် Go memory model အရ synchronization မပါတဲ့ race ရှိတဲ့ program ရဲ့ အပြုအမူကို အာမခံချက် မပေးပါဘူး၊ ဒါကြောင့် 'နည်းနည်းလောက် လွဲတာပါ' လို့ မယူဆသင့်ပါဘူး။
Core concept: shared data တိုင်းမှာ စည်းကမ်း တစ်ခု ရှိရမယ်
Data race ဖြစ်ဖို့ အခြေအနေ သုံးခု တပြိုင်နက် လိုပါတယ်: goroutine နှစ်ခု ဒါမှမဟုတ် အများက memory နေရာ တစ်ခုတည်းကို ထိတယ်၊ အနည်းဆုံး တစ်ခုက ရေးတယ်၊ ပြီးတော့ သူတို့ကြားမှာ synchronization မရှိဘူး။ အဲဒီ သုံးခုထဲက တစ်ခုကို ဖယ်လိုက်ရင် race ပျောက်ပါတယ်။ Data ကို goroutine တစ်ခုတည်းက ပိုင်ဆိုင်ပြီး channel နဲ့ ပို့တာ (sharing ကို ဖယ်တာ)၊ စဖွင့်ပြီးနောက် ဖတ်ပဲ ဖတ်တာ (write ကို ဖယ်တာ)၊ ဒါမှမဟုတ် lock သုံးတာ (synchronization ထည့်တာ) တို့ ဖြစ်ပါတယ်။
sync.Mutex က အသုံးအများဆုံး tool ပါ။ mu.Lock() က lock ကို ယူပြီး တခြား goroutine တစ်ခုက ကိုင်ထားရင် စောင့်ပါတယ်။ mu.Unlock() က lock ကို ပြန်လွှတ်ပါတယ်။ Lock နဲ့ Unlock ကြားက code ကို critical section လို့ ခေါ်ပါတယ်။ Lock ပြီးတာနဲ့ defer mu.Unlock() ကို ချက်ချင်း ရေးပါ၊ ဒါမှ function က ဘယ်လမ်းကြောင်းကနေ return ပြန်ပြန် lock ကို မမေ့မလျော့ ပြန်လွှတ်ပါတယ်။ Mutex ကို သူ ကာကွယ်တဲ့ field တွေနဲ့ struct တစ်ခုတည်းထဲမှာ ထားပြီး pointer receiver method တွေကနေပဲ ထိခွင့်ပေးတာက Go မှာ စံ ပုံစံပါ။ Mutex ကို copy မကူးရပါဘူး၊ copy တစ်ခုက သီးခြား lock တစ်ခု ဖြစ်သွားလို့ပါ။
Counter တစ်ခု၊ flag တစ်ခုလို တန်ဖိုး တစ်ခုတည်းအတွက်ဆိုရင် sync/atomic package က ပိုပေါ့ပါတယ်။ atomic.Int64 ရဲ့ Add, Load, Store, CompareAndSwap တို့က hardware အဆင့်မှာ ခွဲမရတဲ့ operation တွေပါ။ ဒါပေမဲ့ atomic က တန်ဖိုး တစ်ခုချင်းစီကိုပဲ ကာကွယ်ပါတယ်၊ 'balance ကို စစ်ပြီးမှ နုတ်' လို field နှစ်ခု ဒါမှမဟုတ် အဆင့် နှစ်ဆင့် ပါတဲ့ စည်းမျဉ်းအတွက် mutex လိုပါတယ်။ sync.WaitGroup ကတော့ data ကို မကာကွယ်ပါဘူး၊ goroutine တွေ ပြီးဆုံးတာကို စောင့်ပေးပြီး Wait() ပြန်လာတဲ့အခါ သူတို့ ရေးခဲ့တာ အားလုံးကို မြင်ရမယ်လို့ အာမခံပါတယ်။
sync.RWMutex မှာ lock နှစ်မျိုး ပါပါတယ်။ RLock က reader အများကြီးကို တပြိုင်နက် ဝင်ခွင့်ပေးပြီး Lock ကတော့ reader အားလုံး ထွက်တဲ့အထိ စောင့်ပြီး writer တစ်ခုတည်းကိုပဲ ဝင်ခွင့်ပေးပါတယ်။ ဖတ်တာ အများကြီး ရှိပြီး critical section တွေ အရှည်ကြီး ဖြစ်တဲ့အခါမှ အကျိုးရှိပါတယ်၊ တိုတိုလေးဆိုရင် ရိုးရိုး Mutex က ပိုရိုးရှင်းပြီး မကြာခဏ ပိုမြန်ပါတယ်။
| Tool | ဘယ်အချိန် သုံးမလဲ |
|---|---|
| sync.Mutex | Map, slice ဒါမှမဟုတ် field အများကို အတူတူ ပြင်ရတဲ့အခါ |
| sync.RWMutex | ဖတ်တာ အရမ်းများပြီး ရေးတာ ရှားတဲ့အခါ |
| atomic.Int64 / atomic.Bool | တစ်ခုတည်းသော counter ဒါမှမဟုတ် flag |
| Channel | Data ကို goroutine တစ်ခုက ပိုင်ပြီး တခြားသူတွေက message ပို့တဲ့အခါ |
| sync.WaitGroup | Goroutine အားလုံး ပြီးတဲ့အထိ စောင့်ဖို့ |
- Shared data ကို ရှာပါ
- ပိုင်ရှင် ဒါမှမဟုတ် lock တစ်ခု ရွေးပါ
- Lock ယူ၊ defer Unlock ရေး
- Wait() ပြီးမှ ရလဒ်ကို ဖတ်ပါ
Lock က data ကို ကာကွယ်တာ မဟုတ်ပါဘူး၊ lock ကို ယူပြီးမှ data ကို ထိတဲ့ code က ကာကွယ်တာပါ။ Lock ကျော်ပြီး ထိတဲ့ နေရာ တစ်ခုတည်းနဲ့တင် race ပြန်ဖြစ်ပါတယ်။
အထွေထွေ ပုံစံ
type SafeThing struct {
mu sync.Mutex
field Type // guarded by mu
}
func (s *SafeThing) Update(v Type) {
s.mu.Lock()
defer s.mu.Unlock()
// read and write s.field here
}
var hits atomic.Int64 // hits.Add(1), hits.Load()Mutex ကို ကာကွယ်ရမယ့် field တွေနဲ့ အတူ struct ထဲ ထည့်ပြီး pointer receiver method ထဲမှာ Lock နဲ့ defer Unlock ကို တွဲရေးပါ။ တန်ဖိုး တစ်ခုတည်းအတွက်ဆိုရင် atomic type က လုံလောက်ပါတယ်။
Worked example: goroutine 300 ခုက inventory တစ်ခုကို update လုပ်ခြင်း
အောက်က program မှာ goroutine 300 ခုက apple, banana, cherry stock ကို တပြိုင်နက် တိုးကြပါတယ်။ Map ကို Mutex က ကာကွယ်ပြီး request အရေအတွက်ကိုတော့ atomic counter နဲ့ ရေတွက်ပါတယ်။ Map ကို ဘယ်နှခါ run run output က အမြဲ အတူတူ ထွက်ဖို့ key တွေကို sort လုပ်ပြီးမှ print ထုတ်ပါတယ်။
package main
import (
"fmt"
"sort"
"sync"
"sync/atomic"
)
// Inventory is safe for concurrent use: mu guards stock.
type Inventory struct {
mu sync.Mutex
stock map[string]int
}
func (inv *Inventory) Add(item string, n int) {
inv.mu.Lock()
defer inv.mu.Unlock()
inv.stock[item] += n
}
func (inv *Inventory) Snapshot() map[string]int {
inv.mu.Lock()
defer inv.mu.Unlock()
out := make(map[string]int, len(inv.stock))
for k, v := range inv.stock {
out[k] = v
}
return out
}
func main() {
inv := &Inventory{stock: map[string]int{}}
var requests atomic.Int64
var wg sync.WaitGroup
items := []string{"apple", "banana", "cherry"}
for i := range 300 {
wg.Add(1)
go func() {
defer wg.Done()
inv.Add(items[i%len(items)], 1)
requests.Add(1)
}()
}
wg.Wait()
snap := inv.Snapshot()
names := make([]string, 0, len(snap))
for name := range snap {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
fmt.Printf("%s: %d\n", name, snap[name])
}
fmt.Println("requests:", requests.Load())
}Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်
- Mutex next to the data
mu sync.MutexMutex က stock map နဲ့ struct တစ်ခုတည်းထဲမှာ ရှိပါတယ်။ Zero value ဖြစ်တဲ့ Mutex က unlock ဖြစ်ပြီးသား အသုံးပြုလို့ ရတဲ့ lock ပါ၊ constructor မလိုပါဘူး။
- Lock with defer Unlock
defer inv.mu.Unlock()Lock ယူပြီး ချက်ချင်း Unlock ကို defer လုပ်ထားလို့ map update ပြီးတာနဲ့ lock ကို အမြဲ ပြန်လွှတ်ပါတယ်။ Map ကို lock မပါဘဲ တပြိုင်နက် ရေးရင် Go runtime က 'concurrent map writes' fatal error နဲ့ program ကို ရပ်နိုင်ပါတယ်။
- Copy before sharing
for k, v := range inv.stock {Snapshot က lock ကိုင်ထားစဉ် map အသစ်တစ်ခုထဲ copy ကူးပါတယ်။ Map အစစ်ကို ပြန်ပေးလိုက်ရင် ခေါ်သူက lock မပါဘဲ ဖတ်မိပြီး race ပြန်ဖြစ်နိုင်ပါတယ်။
- Atomic counter
requests.Add(1)requests က atomic.Int64 ဖြစ်လို့ Add က ခွဲမရတဲ့ operation တစ်ခုပါ။ Number တစ်ခုတည်းကို တိုးဖို့ mutex မလိုပါဘူး။
- Wait before reading
wg.Wait()Wait() ပြန်လာပြီးမှ goroutine 300 ခုလုံး ပြီးဆုံးပြီး သူတို့ရေးခဲ့တာ အားလုံး မြင်ရပါတယ်။ ဒီမတိုင်ခင် ဖတ်ရင် ရလဒ်က တစ်ဝက်တစ်ပျက်ပဲ ရနိုင်ပါတယ်။
apple: 100
banana: 100
cherry: 100
requests: 300Race detector ကို run ခြင်း
Race ပါတဲ့ code က အများအားဖြင့် မှန်ကန်တဲ့ အဖြေ ထွက်လေ့ရှိလို့ output ကို ကြည့်ရုံနဲ့ မရှာနိုင်ပါဘူး။ Go မှာ -race flag နဲ့ race detector ပါပါတယ်။ Program က run နေစဉ် memory access တိုင်းကို စောင့်ကြည့်ပြီး synchronization မပါတဲ့ access နှစ်ခု တွေ့ရင် goroutine နှစ်ခုလုံးရဲ့ stack trace ကို report လုပ်ပါတယ်။ Platform အများစုမှာ cgo နဲ့ C compiler လိုအပ်ပါတယ်။
go run -race racy_counter.go # run one program with detection on
go test -race ./... # run every test in the module with detection onProblem section က counter program ကို -race နဲ့ run ရင် အောက်ပါလို report မျိုး ရပါတယ်။ Address, goroutine နံပါတ်နဲ့ line နံပါတ်တွေက run တိုင်း ကွဲပြားပါတယ်၊ ဒါကြောင့် ဒါကို နမူနာ အတိုချုပ်အဖြစ်ပဲ ယူပါ။ Race တွေ့ရင် program က exit status 66 နဲ့ ထွက်ပါတယ်။
==================
WARNING: DATA RACE
Read at 0x00c000014108 by goroutine 8:
main.main.func1()
/home/you/racy_counter.go:15 +0x84
Previous write at 0x00c000014108 by goroutine 7:
main.main.func1()
/home/you/racy_counter.go:15 +0x96
==================
Found 1 data race(s)
exit status 66Report မရှိတာ race မရှိတာ မဟုတ်ပါ
Race detector က တကယ် run သွားတဲ့ code လမ်းကြောင်းကိုပဲ စစ်နိုင်ပါတယ်။ Test တွေက concurrent လမ်းကြောင်းကို မ run ခဲ့ရင် race ကို မတွေ့ပါဘူး။ Program ကိုလည်း နှေးစေပြီး memory ပိုစားလို့ production မှာ အမြဲဖွင့်ထားလေ့ မရှိပါဘူး၊ test နဲ့ staging မှာ သုံးပါ။
လက်တွေ့ project တွေမှာ
လက်တွေ့ Go service တွေမှာ ဘယ်လို သုံးလဲ
HTTP server ဆိုတာ concurrency program တစ်ခုပါ: net/http က request တစ်ခုစီကို ကိုယ်ပိုင် goroutine နဲ့ run ပါတယ်။ ဒါကြောင့် handler တွေ မျှသုံးတဲ့ package-level map၊ cache ဒါမှမဟုတ် counter တိုင်းက လိုင်းပေါ် တက်တဲ့ နေ့ကတည်းက race ဖြစ်နိုင်ပါတယ်။ Load နည်းတဲ့ local test မှာ မပေါ်ဘဲ traffic များလာမှ ပေါ်လာလေ့ရှိပါတယ်။
- In-memory cache: map[string]Item ကို sync.RWMutex နဲ့ ကာကွယ်ပြီး Get အတွက် RLock၊ Set အတွက် Lock ကို သုံးပါတယ်။
- Metrics: request count, error count တို့ကို atomic.Int64 နဲ့ ရေတွက်ပြီး /metrics endpoint က Load နဲ့ ဖတ်ပါတယ်။
- Rate limiter နဲ့ connection pool တွေမှာ 'စစ်ပြီးမှ ယူ' ဆိုတဲ့ စည်းမျဉ်း ပါလို့ mutex တစ်ခုအောက်မှာ အဆင့်နှစ်ဆင့်လုံး လုပ်ရပါတယ်။
- Team အများစုက CI pipeline ထဲမှာ go test -race ./... ကို ထည့်ထားပြီး race report တစ်ခုကို test fail တစ်ခုလို သဘောထားပါတယ်။
အမှားများ
Synchronization မှာ ဖြစ်လေ့ရှိတဲ့ အမှားများ
Mutex ပါတဲ့ struct ကို value နဲ့ copy ကူးခြင်း
func (c Counter) Inc() လို value receiver က method ခေါ်တိုင်း struct ကို copy ကူးပါတယ်၊ ဒါကြောင့် lock ကော data ကော copy ပေါ်မှာပဲ ပြောင်းပြီး မူလ object က မပြောင်းပါဘူး။ Pointer receiver (c *Counter) ကို သုံးပါ။ go vet ရဲ့ copylocks check က ဒီအမှားကို ဖမ်းပေးပါတယ်။
wg.Add ကို goroutine အထဲမှာ ခေါ်ခြင်း
go func() { wg.Add(1); ... }() လို ရေးရင် goroutine စမ run ခင် main က wg.Wait() ကို ရောက်သွားပြီး counter သုည ဖြစ်နေလို့ ချက်ချင်း ပြန်လာနိုင်ပါတယ်။ wg.Add(1) ကို go statement မတိုင်ခင် ခေါ်ပါ။ Go 1.25 နဲ့ နောက်ပိုင်း version တွေမှာ Add နဲ့ Done ကို အလိုအလျောက် တွဲပေးတဲ့ wg.Go(f) လည်း ရှိပါတယ်။
Atomic နဲ့ ရိုးရိုး access ကို ရောသုံးခြင်း ဒါမှမဟုတ် အဆင့်နှစ်ဆင့်ကို ခွဲ lock ခြင်း
Variable တစ်ခုကို နေရာတစ်ခုမှာ atomic နဲ့ ရေးပြီး တခြားနေရာမှာ ရိုးရိုး ဖတ်ရင် race ပဲ ဖြစ်ပါတယ်။ အလားတူ Balance() ကို lock နဲ့ ဖတ်ပြီး ပြီးမှ Withdraw() ကို သီးခြား lock နဲ့ ခေါ်ရင် operation တစ်ခုချင်းစီ လုံခြုံပေမဲ့ နှစ်ခုကြားမှာ တခြား goroutine က ငွေ ထုတ်သွားနိုင်ပါတယ်။ စစ်ဆေးတာနဲ့ ပြောင်းတာကို lock တစ်ခုတည်းအောက်မှာ လုပ်ပါ။
Best Practices
Best practices
- Mutex ကာကွယ်တဲ့ field တွေကို mutex အောက်မှာ စီရေးပြီး '// guarded by mu' comment ထည့်ပါ။
- Critical section ကို တိုတိုထားပါ၊ lock ကိုင်ထားစဉ် network call ဒါမှမဟုတ် sleep မလုပ်ပါနဲ့။
- Internal map ဒါမှမဟုတ် slice ကို ပြန်ပေးမယ့်အစား copy ကို ပြန်ပေးပါ။
- Concurrent code တိုင်းအတွက် -race နဲ့ test တစ်ခု ရေးပြီး CI ထဲမှာ အမြဲ run ပါ။
Mini challenge
Mini challenge: overdraft မဖြစ်တဲ့ bank account
Goroutine အများကြီးက တပြိုင်နက် ငွေထုတ်နိုင်တဲ့ Account type ကို ရေးပါ။ Balance 500 ရှိတဲ့ account ကနေ goroutine 100 ခုက 10 စီ ထုတ်ကြပါမယ်။ Run တိုင်း အောင်မြင်တာ 50 ခု၊ ငြင်းခံရတာ 50 ခုနဲ့ balance 0 အတိအကျ ထွက်ရပါမယ်။
- Account ထဲမှာ sync.Mutex နဲ့ balance field ထားပါ
- Withdraw က balance စစ်တာနဲ့ နုတ်တာကို lock တစ်ခုတည်းအောက်မှာ လုပ်ပြီး မလုံလောက်ရင် ErrInsufficientFunds ကို ပြန်ပေးရမယ်
- အောင်မြင်/ငြင်းခံရ အရေအတွက်ကို atomic.Int64 နဲ့ ရေတွက်ပါ
- wg.Wait() ပြီးမှ ရလဒ်သုံးခုကို print ထုတ်ပါ
package main
import (
"errors"
"fmt"
"sync"
"sync/atomic"
)
var ErrInsufficientFunds = errors.New("insufficient funds")
type Account struct {
// TODO: a mutex and the balance it guards
}
func (a *Account) Deposit(amount int) {
// TODO: lock, add, unlock
}
func (a *Account) Withdraw(amount int) error {
// TODO: check AND subtract while holding the lock
return nil
}
func (a *Account) Balance() int {
// TODO: read the balance under the lock
return 0
}
func main() {
acct := &Account{}
acct.Deposit(500)
var ok, rejected atomic.Int64
var wg sync.WaitGroup
// TODO: start 100 goroutines that each withdraw 10 and count the outcome
wg.Wait()
fmt.Println(ok.Load(), rejected.Load(), acct.Balance())
}ရလဒ်: Run တိုင်း succeeded: 50, rejected: 50, balance: 0 ကို print ထုတ်ပါတယ်။ ဘယ် goroutine တွေ အောင်မြင်လဲဆိုတာ run တိုင်း ကွဲနိုင်ပေမဲ့ အရေအတွက်က မပြောင်းပါဘူး။
အရိပ်အမြွက် ကြည့်ရန်
Withdraw ရဲ့ ပထမဆုံး line နှစ်ကြောင်းက a.mu.Lock() နဲ့ defer a.mu.Unlock() ဖြစ်ပါစေ။ အဲဒီနောက်မှ if a.balance < amount နဲ့ စစ်ပါ။ Goroutine ထဲမှာ errors.Is(err, ErrInsufficientFunds) နဲ့ ရလဒ်ကို ခွဲခြားပါ။
အဖြေ ကြည့်ရန်
package main
import (
"errors"
"fmt"
"sync"
"sync/atomic"
)
var ErrInsufficientFunds = errors.New("insufficient funds")
type Account struct {
mu sync.Mutex
balance int // guarded by mu
}
func (a *Account) Deposit(amount int) {
a.mu.Lock()
defer a.mu.Unlock()
a.balance += amount
}
// Withdraw checks and updates under ONE lock, so two goroutines
// cannot both see enough money and both take it.
func (a *Account) Withdraw(amount int) error {
a.mu.Lock()
defer a.mu.Unlock()
if a.balance < amount {
return ErrInsufficientFunds
}
a.balance -= amount
return nil
}
func (a *Account) Balance() int {
a.mu.Lock()
defer a.mu.Unlock()
return a.balance
}
func main() {
acct := &Account{}
acct.Deposit(500)
var ok, rejected atomic.Int64
var wg sync.WaitGroup
for range 100 {
wg.Add(1)
go func() {
defer wg.Done()
if err := acct.Withdraw(10); errors.Is(err, ErrInsufficientFunds) {
rejected.Add(1)
} else {
ok.Add(1)
}
}()
}
wg.Wait()
fmt.Println("succeeded:", ok.Load())
fmt.Println("rejected:", rejected.Load())
fmt.Println("balance:", acct.Balance())
}Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
မှတ်ထားရမယ့် အချက်များ
- Goroutine နှစ်ခုက memory တစ်နေရာကို sync မပါဘဲ ထိပြီး တစ်ခုက ရေးရင် data race ဖြစ်ပါတယ်။
- Map နဲ့ field အများအတွက် sync.Mutex ကို သုံးပြီး Lock ပြီးတာနဲ့ defer Unlock ရေးပါ။
- Counter တစ်ခုတည်းအတွက် atomic.Int64၊ goroutine တွေ ပြီးတာ စောင့်ဖို့ sync.WaitGroup ကို သုံးပါ။
- go test -race က run သွားတဲ့ လမ်းကြောင်းထဲက race တွေကို ရှာပေးလို့ CI ထဲမှာ ထည့်ထားပါ။
Data Race Detector — Go