Tuesday, September 29, 2020

golang mutexes arn't recursive like in C#

golang mutex are a lot different from C# locks. In C#, locking on an object will check whether the current thread has already locked on the object or not. If it has, the locking is successful. However in golang, each mutex.Lock() attempts to lock regardless whether code/goroutine has already been locked or not.
In the above program, the 2nd lock call will deadlock.