Hacker News new | ask | show | jobs
by AndyKelley 825 days ago
For spawning a thread you're literally asking for the stack of the thread to be memory mapped. I fail to see how this is "behind your back".

You also linked specifically to the POSIX threads implementation of thread spawning, which is by definition supposed to play nicely with the libc posix threads API, which expects you to use the libc allocator in combination with POSIX threads API, so that's what it does.

You might as well accuse the mmap() function in the zig standard library of allocating behind your back.

3 comments

It’s something Zig touts when compared to other languages(1). The idea is that in the end it’s a convention that an allocator needs to be passed to indicate that the function allocates, which not even the stdlib adheres religiously to. I’m fine with it since I do believe a library writer should know best what works with their library.

1. https://ziglang.org/learn/why_zig_rust_d_cpp/#no-hidden-allo...

The behind your back part is probably referring to the Args payload bouncing through a heap allocation. It isn't explicit on the signature it's making an allocation. The function has no choice though unless you leave it up to the user to keep the payload allocation live until the thread terminates.
Exactly
he was pointing out that it does, and he was not applying to it the label "behind your back, that's why he said "except for". the wording makes perfect sense.
> Similarly zig’s stdlib shouldn’t allocate behind your back, except for thread spawn where it does

shouldn't X, exceptor for Y where it does [X]

It makes perfect sense that GP was saying "thread spawn allocates behind your back".