goparkunlock vs notetsleepg in runtime/timers.go

261 views
Skip to first unread message

Alexander Morozov

unread,
Oct 21, 2016, 5:55:31 PM10/21/16
to golang-dev
Hello!
I'm trying to understand the code in src/runtime/timers.go and found that it uses two functions to "freeze" timers goroutine
goparkunlock and notetsleepg. I wonder what's the difference between goparkunlock and notetsleepg with negative ns . Is it related to "faketime"?
Thanks!

Austin Clements

unread,
Oct 21, 2016, 6:06:48 PM10/21/16
to Alexander Morozov, golang-dev
This is not related to faketime. These are just two different synchronization mechanisms used for two different purposes. We can't use gopark for both cases because gopark doesn't understand timeouts (it would be turtles all the way down :). We probably could use notetsleepg for both, but notetsleepg consumes an OS thread for the entire duration of the sleep (so the OS ultimately implements the time keeping). By combining the two mechanisms, timerproc doesn't consume any OS resources if there are no timers.


--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Morozov

unread,
Oct 21, 2016, 6:23:02 PM10/21/16
to Austin Clements, golang-dev

Thanks for a thorough explanation, Austin!

Reply all
Reply to author
Forward
0 new messages