normal mode and starve mode of sync.Mutex and runtime mutex?

178 views
Skip to first unread message

xie cui

unread,
Jan 31, 2021, 10:15:23 AM1/31/21
to golang-nuts
why mutex in runtime do not need starve mode?

jake...@gmail.com

unread,
Jan 31, 2021, 11:38:08 AM1/31/21
to golang-nuts
What makes you think it does not? Have you looked at Mutex.lockSlow()? I have not really worked through the algorithm, but the comments do mention starvation mode.

xie cui

unread,
Jan 31, 2021, 9:56:55 PM1/31/21
to golang-nuts
mutex in sync package and runtime is different,
i do not see there is a starving mode.

robert engels

unread,
Jan 31, 2021, 10:07:10 PM1/31/21
to xie cui, golang-nuts
Not sure the runtime needs it - as all lock usages are known - so the users in the runtime can ’negotiate’ fairness through other means for a particular mutex.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0cc1fae8-6c22-4e40-9645-425d12bb909dn%40googlegroups.com.

Ian Lance Taylor

unread,
Feb 1, 2021, 12:22:19 AM2/1/21
to robert engels, xie cui, golang-nuts
On Sun, Jan 31, 2021 at 7:07 PM robert engels <ren...@ix.netcom.com> wrote:
>
> Not sure the runtime needs it - as all lock usages are known - so the users in the runtime can ’negotiate’ fairness through other means for a particular mutex.

Yes. The point of starvation mode in sync.Mutex is to avoid high tail
latency for highly contended mutexes, in which one set of goroutines
acquiring the mutex can starve a different set of goroutines waiting
for the mutex. The runtime does not have highly contended mutexes.
When we discover a highly contended mutex in the runtime, we change
the code to use a different approach.

That is, sync.Mutex has to work reasonably well for any Go program.
The runtime.mutex type only has to work well for the runtime package.

Ian


> On Jan 31, 2021, at 8:56 PM, xie cui <cuiw...@gmail.com> wrote:
>
> mutex in sync package and runtime is different,
> mutex in runtime package is here, https://github.com/golang/go/blob/master/src/runtime/lock_futex.go#L46
> i do not see there is a starving mode.
>
> On Monday, February 1, 2021 at 12:38:08 AM UTC+8 jake...@gmail.com wrote:
>>
>> What makes you think it does not? Have you looked at Mutex.lockSlow()? I have not really worked through the algorithm, but the comments do mention starvation mode.
>>
>> On Sunday, January 31, 2021 at 10:15:23 AM UTC-5 cuiw...@gmail.com wrote:
>>>
>>> why mutex in runtime do not need starve mode?
>
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0cc1fae8-6c22-4e40-9645-425d12bb909dn%40googlegroups.com.
>
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/E5ADD213-563A-4F32-9467-3F9FC82EDF38%40ix.netcom.com.
Reply all
Reply to author
Forward
0 new messages