package main

import (
	"fmt"
	"sync"

	"go4.org/syncutil/syncdebug"
)

// section: main
func main() {
	var wg sync.WaitGroup
	wg.Add(1)
	var mu syncdebug.RWMutexTracker

	var count int

	go func() {
		for i := 0; i < 5; i++ {
			mu.Lock()
			defer mu.Unlock()
			count = i
			fmt.Println(count)
		}
		wg.Done()
	}()

	wg.Wait()
}

// section: main

/*
// section: get
go get go4.org/syncutil/syncdebug
// section: get

// section: output
$ go run ./main.go
2020/06/04 08:46:26 Lock at goroutine 18 [running]:
go4.org/syncutil/syncdebug.(*RWMutexTracker).Lock(0xc0000ae180)
        /Users/corylanou/go/pkg/mod/go4.org@v0.0.0-20180809161055-417644f6feb5/syncutil/syncdebug/syncdebug.go:129 +0xf8
main.main.func1(0xc0000ae180, 0xc0000b2010, 0xc0000b2004)
        /Users/corylanou/projects/gopherguides/learn/_training/fundamentals/concurrency-sync/src/examples/mutex/bug/debug/main.go:20 +0xb2
created by main.main
        /Users/corylanou/projects/gopherguides/learn/_training/fundamentals/concurrency-sync/src/examples/mutex/bug/debug/main.go:18 +0xad
0
2020/06/04 08:46:27 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
2020/06/04 08:46:28 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
2020/06/04 08:46:29 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
2020/06/04 08:46:30 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
2020/06/04 08:46:31 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
2020/06/04 08:46:32 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
2020/06/04 08:46:33 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
2020/06/04 08:46:34 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
2020/06/04 08:46:35 Mutex 0xc0000ae180: waitW 1 haveW 1   waitR 0 haveR 0
// section: output

*/
