为什么Apache的MPM prefork.c使用互斥来保护接受()? [英] Why does Apache MPM prefork.c use a mutex to protect accept()?
问题描述
我坐下来阅读的 Apache的MPM prefork.c 这code使用的是名为 accept_mutex
变量prevent多个线程调用接受()
。这很奇怪,因为据我所知 接受()
是线程安全的。
I sat down and read Apache's MPM prefork.c and this code is using a variable called accept_mutex
to prevent multiple threads from calling accept()
. This is strange because as far as I know accept()
is thread-safe.
时accept()方法的线程安全吗?这是一个平台的兼容性问题?如果是的话什么平台实现了一个非线程安全的接受()
?
Is accept() thread safe? Is this a platform compatibility issue? If so what platform implements a non-thread-safe accept()
?
推荐答案
这是在解释Apache的性能调整文档,在接受()
连载 - 多个套接字。简单地说,至少有一些操作系统下,传入的连接将唤醒的所有的是在等待传入连接的Apache进程的select()
或调查()
,但会造成接受()
失败的所有,但其中的一个。这是低效,因此一个互斥被用来确保只有一个进程接受一次传入连接
This is explained in the Apache performance tuning documentation, under "accept()
Serialization - multiple sockets". In brief, under at least some operating systems, an incoming connection will wake all Apache processes that are waiting for incoming connections in select()
or poll()
, but will cause the accept()
to fail on all but one of them. This is inefficient, so a mutex is used to ensure that only one process accepts an incoming connection at a time.
这篇关于为什么Apache的MPM prefork.c使用互斥来保护接受()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!