When working with a concurrent program in Go
, we use var mutex sync.Mutex
and then if we have to write execute some synchronized code block, we call mutex.Lock()
and mutex.Unlock()
. Now I have some doubts here:
1) Is there only one instance of mutex
i.e. if mutex
is being used for locking for operation of CodeBlockA, and at the same time some other goroutine B
has to use it for some other CodeBlockB that also uses mutex
, will goroutine B
be blocked till goroutine A
relieves mutex
.
2) Is it possible that we can have more instances of muteness guarding their own dedicated code blocks.