News for hackers. Stuff that matters.
Re:Fork is not my favourite syscall by majewsky on Thursday January 04, 2018 @08:26AM (#16070155)
> it's essentially what happens when you create a thread nowadays

I'm not familiar with the guts of threading libs, but AFAIK the syscall that spawns threads is clone(), which takes a function pointer and a stack pointer, so it very much does not start "with the same data structures and the same execution point".

Re:Fork is not my favourite syscall by tialaramex on Thursday January 04, 2018 @11:35AM (#16071632)
You're talking about the C library function clone(). The actual system call "clone" on Linux doesn't care about functions, or stack pointers, it just sets a flag like the system call fork did. Everything else is implemented in the library by checking the return code.

This is all fine, there are two scenarios, neither of which is the imagined "race" described above:

1. "Fork-and-exec" Our new execution context will actually run a different program. We immediately do so, the new program doesn't care about most of the state of the old program, it throws that state away, including locks that were held by the old program's allocator.

2. "New Thread" Our new context will share all the state, if another thread has a process-wide lock for some reason, it can and should apply to us too. If it took a thread-specific lock, we're not that thread, so we already don't care.

Re:Fork is not my favourite syscall by majewsky on Friday January 05, 2018 @06:27AM (#16077966)
> You're talking about the C library function clone().

Huh? I saw that the manpage for clone() is in section 2, which AFAIK means it's kernel API, whereas C library functions are usually in section 3. Am I mistaken?

Even syscalls(2) refers to clone(2) in its list of syscalls.

Re:Fork is not my favourite syscall by tialaramex on Friday January 05, 2018 @12:33PM (#16080035)
Yeah, no.

You are correct that the manual section 2 is "for" system calls, but in practice today these are just the lowest level of the C library, and not the actual system calls.

My copy of the clone(2) manual page hints at this by commenting /* For the prototype of the raw system call, see NOTES */

and more explicitly in its body text by saying "The main text describes the wrapper function; the differences for the raw system call are described toward the end of this page."

Other modern stuff is the same way, the section 2 documentation is describing what an ordinary C programmer needs to know, but if you're say, implementing the C standard library or writing a compiler for a language that runs on the bare metal you need to read the kernel documentation which is not provided as manual pages.

Re:Fork is not my favourite syscall by mcguire on Thursday January 04, 2018 @11:25AM (#16071563)
Clone() came much, much later. In fact, the original thread-creation syscall was vfork() in BSD, IIRC.