Syscalls inside loops + runtime.KeepAlive

94 views
Skip to first unread message

Caleb Spare

unread,
Mar 29, 2017, 12:43:02 PM3/29/17
to golang-nuts
I have a question about this runtime.KeepAlive call:

https://github.com/golang/go/blob/041ecb697f0e867a2bb0bf219cc2fd5f77057c2e/src/os/dir_unix.go#L68

(There are other examples in the stdlib as well, I think.)

It seems to me that, strictly speaking, KeepAlive is unnecessary here
since the compiler/runtime cannot know whether the loop will terminate
before the result of the ReadDirent is seen. Is that true?

I'm not arguing that the KeepAlive should be removed; it's probably
best to stick with the pattern syscall(f.Fd(), ...);
runtime.KeepAlive(f) in most cases. I'm just checking my understanding
here.

Thanks!
Caleb

Ian Lance Taylor

unread,
Mar 29, 2017, 4:03:46 PM3/29/17
to Caleb Spare, golang-nuts
Yes, I think you are correct.

Ian

Caleb Spare

unread,
Apr 5, 2017, 6:01:37 PM4/5/17
to Ian Lance Taylor, golang-nuts
Thanks, Ian.
Reply all
Reply to author
Forward
0 new messages