Get the latest tech news
Golang Sync Mutex: Normal and Starvation Mode
Mutex in Go has two main flows: Lock and Unlock and 2 modes: Normal and Starvation Mode. The state field of mutex is a 32-bit integer that represents the current state, it’s divided into multiple bits that encode various pieces of information about the mutex.
Golang Sync Mutex: Normal and Starvation ModeMutex, or MUT ual EX clusion, in Go is basically a way to make sure that only one goroutine is messing with a shared resource at a time. Unlike the state field, sema doesn’t have a specific bit layout and relies on runtime internal code to handle the semaphore logic. Mutex in Normal ModeAs a result, the goroutine that just woke up might frequently lose the race to the new contenders and get put back at the front of the queue.
Or read this on Hacker News