On Sat, Jun 3, 2023 at 12:35 AM fliter <imc...@gmail.com> wrote:
>
>
> In sync/mutex.go, there is a comment like the following:
>
> ```go
> // Mutex fairness.
> //
> // Mutex can be in 2 modes of operations: normal and starvation.
> // In normal mode waiters are queued in FIFO order, but a woken up waiter
> // does not own the mutex and competes with new arriving goroutines over
> // the ownership. New arriving goroutines have an advantage -- they are
> // already running on CPU and there can be lots of them, so a woken up
> // waiter has good chances of losing. In such case it is queued at front
> // of the wait queue. If a waiter fails to acquire the mutex for more than 
> 1ms,
> // it switches mutex to the starvation mode.
> ```
>
>
> I wonder if the waiter here refers to the goroutine at the head of the queue, 
> or any goroutine in the queue?

In that comment "waiter" refers to the goroutine at the head of the
queue.  When a mutex is unlocked, it wakes up the first waiter, if
any.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXosL%3D_R5raCpAi9y8bfDkdTabeTKyiK2bV_EaqpsjkNA%40mail.gmail.com.

Reply via email to