News for hackers. Stuff that matters.
Re:On Go, Portability, and System Interfaces by pcwalton on Tuesday September 22, 2015 @07:12PM (#10262341)
Using the syscall interface is a lot faster in Go than calling to libc, because the system libc is going to expect large stacks and so you incur the overhead of a stack switch when you switch out of M:N threading into the C world. I assume that's why Go calls syscalls to begin with.
Re:On Go, Portability, and System Interfaces by zaphar on Tuesday September 22, 2015 @08:13PM (#10262599)
The correct go way to do this is to use conditional compilation and hide your platform specific optimizations in a lib_{linux,darwin,...}.go file with the slower default in a file that only gets compiled if the other files don't.

And indeed this is how the stdlib does it. If the rest of the go community is not adopting this practice then they aren't following good Idioms in their Go code.

Re:On Go, Portability, and System Interfaces by awalton on Wednesday September 23, 2015 @01:28AM (#10263454)
And I totally would have agreed with the author of this article if the tl;dr of the article was just the first sentence you wrote.

Unfortunately, sanity did not prevail today.

Re:On Go, Portability, and System Interfaces by teacup50 on Tuesday September 22, 2015 @07:45PM (#10262503)
However, calling directly into the syscall interface is illegal on most platforms other than Linux.

I'm not sure Go can fix this without getting rid of their M:N threading.

Re:On Go, Portability, and System Interfaces by pjc50 on Wednesday September 23, 2015 @09:39AM (#10264895)
I'm assuming you mean "unsupported" rather than "prohibited by law", although with the DMCA one can never be sure.
Re:On Go, Portability, and System Interfaces by 4ad on Tuesday September 22, 2015 @08:13PM (#10262596)
On Windows and Solaris, Go doesn't do its own syscalls.
Re:On Go, Portability, and System Interfaces by teacup50 on Tuesday September 22, 2015 @08:16PM (#10262607)
How about OS X?

(and, how does that work when calling into userspace APIs that assume fixed 1:1 thread/stack correlation)

Re:On Go, Portability, and System Interfaces by 4ad on Tuesday September 22, 2015 @08:25PM (#10262631)
On OS X Go does its own system calls, ignoring the OS X guidlines.

Go uses M:N scheduling, but you still have N threads with (relatively) large stacks. When calling into C code, Go switches stacks, so it runs on the (relatively) large stack where C code can run. Of course there's some overhead associated with this, but system call overhead is large on its own compared to this anyway.

During the system call the thread (obviously) can't run any other Go code, but that's ok, the runtime makes sure there are always threads available to run user Go code (that's one reason why the runtime stands between user code and system calls).

Re:On Go, Portability, and System Interfaces by 4ad on Wednesday September 23, 2015 @06:02AM (#10264172)
No, the stack switch overhead is trivial. As explain in my other comment, Go does system calls in order not to have any dependencies on target libraries.