Issuing a blocking system call

110 views
Skip to first unread message

Florian Weimer

unread,
Mar 3, 2021, 5:00:32 PM3/3/21
to golan...@googlegroups.com
Do I have to tell the runtime that a system call is blocking? For
example, I use this code snippet to perform a blocking ioctl:

conn, err := file.SyscallConn()
if err != nil {
return
}
err1 := conn.Control(func(fd uintptr) {
_, _, err2 := syscall.Syscall(syscall.SYS_IOCTL,
fd, uintptr(req), 0)
if err2 != 0 {
err = err2
}

})

And the syscall can block until some hardware timeout occurs. The
file descriptor has already been transitioned to blocking mode using
file.FD(). Is there anything else left to do, so that the runtime
knows it may have to spawn a new worker thread or something like that?

Ian Lance Taylor

unread,
Mar 4, 2021, 5:49:12 PM3/4/21
to Florian Weimer, golang-nuts
You do not have to tell the runtime anything special. This kind of
code will work as is.

You may want to consider using the golang.org/x/sys/unix package and
functions like IoctlGetInt, but the above should also work.

Ian
Reply all
Reply to author
Forward
0 new messages