goparkunlock vs notetsleepg in runtime/timers.go

260 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Alexander Morozov

belum dibaca,
21 Okt 2016, 17.55.3121/10/16
kepadagolang-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

belum dibaca,
21 Okt 2016, 18.06.4821/10/16
kepadaAlexander 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

belum dibaca,
21 Okt 2016, 18.23.0221/10/16
kepadaAustin Clements, golang-dev

Thanks for a thorough explanation, Austin!

Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru