From f16bfef10354f1f70bed6c342f9644a171ba8eca Mon Sep 17 00:00:00 2001 From: oscarzhou Date: Thu, 29 Apr 2021 22:50:28 +1200 Subject: [PATCH] doc: add explanation of sync.Mutex --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f78b11..8eda6a6 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,17 @@ select { default: // receive when c is blocked } -``` \ No newline at end of file +``` + +## sync.Mutex + +Channels are great for communication, but what if we don't need communication? + +What if we just want to make sure only one goroutine can access a variable at a time to avoid conflicts? This concept is called `mutual exclusion`, and the conventional name for the data structure that provides it is `mutex` + +Go's standard library provides mutual exclusion with `sync.Mutex` and its two methods: `Lock` and `Unlock` + + +## sync.WaitGroup + +https://tutorialedge.net/golang/go-waitgroup-tutorial/ \ No newline at end of file