I have some question about channel and mutex operation

95 views
Skip to first unread message

UK

unread,
Nov 25, 2022, 11:36:00 AM11/25/22
to golang-nuts
channel and mutex eventually call futexsleep(in runtime source) when need to block

but  when I tested sync.Mutex lock 10000 times, there is only 8 threads..

futex is os level operation(syscall), then futex sleep os-level thread(not goroutine)

right? somebody help me understand...

Ian Lance Taylor

unread,
Nov 25, 2022, 12:07:43 PM11/25/22
to UK, golang-nuts
It's not accurate to say that channel and mutex operations always call
futexsleep. Those operations will park the goroutine until it is
ready and the thread will enter the scheduler to find another
goroutine to run. futexsleep is used by a thread when there is no
goroutine available to schedule.

Ian

UK

unread,
Nov 27, 2022, 7:50:19 PM11/27/22
to Ian Lance Taylor, golang-nuts
Thank you for the clarification. i will check again source code. Thank you! 

2022년 11월 26일 (토) 오전 2:07, Ian Lance Taylor <ia...@golang.org>님이 작성:
Reply all
Reply to author
Forward
0 new messages