I looked at commit, where Ulrich Drapper added this code to glibc, and there was no explanation in the commit log (or elsewhere).
Take a look at the Linux fork implementation though:
return _do_fork(SIGCHLD, 0, 0, NULL, NULL, 0);
And here is clone :
return _do_fork(clone_flags, newsp, 0, parent_tidptr, child_tidptr, tls);
Obviously, they are almost the same. The only difference is that when you call clone you can set various flags, specify the stack size for the new process, etc. fork does not accept any arguments.
Looking at the Drepper code, the clone flags CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD . If fork used, the only value will be SIGCHLD .
Here's what the clone manpage says about these extra flags:
CLONE_CHILD_CLEARTID (since Linux 2.5.49) Erase child thread ID at location ctid in child memory when the child exits, and do a wakeup on the futex at that address. The address involved may be changed by the set_tid_address(2) system call. This is used by threading libraries. CLONE_CHILD_SETTID (since Linux 2.5.49) Store child thread ID at location ctid in child memory.
... And you can see that it passes a pointer to where the kernel should first store the identifier of the child thread, and then wake up futex. Does glibc make futex wait at this address somewhere? I dont know. If so, this explains why Drepper decided to use clone .
(And if not, this will be another example of extreme torsional motion accumulation, which is our favorite glibc! If you would like to find nice, clean, well-groomed code, just keep moving and go look at musl libc!)