package main
import (
)"sync"
)
type data struct {
sync.Mutex
}
func (d data) test (s string) {
d.Lock()
defer d.Unlock()
for i:=0;i<5 ;iPP {
println(s,i)
//time.Sleep(time.Second)
}
}
func test_lock () {
var wg sync.WaitGroup
wg.Add(3)
var d data
go func() {
defer wg.Done()
d.test("write")
}()
go func() {
defer wg.Done()
d.test("read")
}()
go func() {
defer wg.Done()
d.test("new")
}()
wg.Wait()
}
func main () {
test_lock()
}
d.lock is blocked. Shouldn"t you print anything else after all the write has been typed? Why can new get a lock after write prints part of it