Project

General

Profile

« Previous | Next » 

Revision 3563e138

Added by byroot (Jean Boussier) over 2 years ago

thread_pthread.c: Use a fork_gen to protect against fork instead of getpid()

[Feature #19443]

Until recently most libc would cache getpid() so this was a cheap check to make.

However as of glibc version 2.25 the PID cache is removed and calls to getpid() always
invoke the actual system call which significantly degrades the performance of existing applications.

The reason glibc removed the cache is that some libraries were bypassing fork(2)
by issuing system calls themselves, causing stale cache issues.

That isn't a concern for Ruby as bypassing MRI's primitive for forking would
render the VM unusable, so we can safely cache the PID.