我最充分地回答所有分问题;我很抱歉,其中一些问题比理想的情况更模糊:
If there is a
possibility that library code has
registered pthread_atfork handlers
which are not async-signal-safe, does
this negate the safety of fork?
是的。 rel=“noreferer”>fork documentation 明确提到这一点:
When the application calls fork() from a signal handler and any of the
fork handlers registered by pthread_atfork() calls a function that is
not asynch-signal-safe, the behavior is undefined.
当然,这意味着你可以实际使用pthread_atfork (
,其用意是使多面阅读的图书馆具有透明度,使其相信这些图书馆是单一阅读的,因为光辉的同步功能中没有一个是合成孔径-信号-安全;这被认为是光谱中的一个缺陷,见。 http://www. opengroup.org/austin/aardvark/latest/xshbug3.txt (关于“L16723”的研究)。
Does
the answer depend on whether the
thread in which the signal handler is
running could be in the middle of
using a resource that the atfork
handlers need? Or said a different
way, if the atfork handlers make use
of synchronization resources (mutexes,
etc.) but fork is being called from a
signal handler which executed in a
thread that never accesses these
resources, is the program conforming?
严格地说,答案是没有的,因为根据具体情况,职能要么是作为同义词,要么是不是;没有“在某些情况下安全”的概念。 在实践中,你可能完全放弃,但你会很容易受到cl然的、但又不正确的执行,从而不以你所期望的方式分割其资源。
Building on this question, if
"thread-safe" forking is implemented
internally in the system library using
the idioms suggested by pthread_atfork
(obtain all locks in the prefork
handler and release all locks in both
the parent and child postfork
handlers), then is fork ever safe to
use from signal handlers in a threaded
program? Isn t it possible that the
thread handling the signal could be in
the middle of a call to malloc or
fopen/fclose and holding a global
lock, resulting in deadlock during
fork?
如果能以这种方式实施,那么,你从信号手里收回fork(>
>,永远不会安全,因为如果电话已经听起来,试图获得锁可能会陷入僵局。 但这意味着使用这种方法的实施不会符合要求。
仅举一例,它就没有这样做了,而是采取了两种做法:首先,它获得的锁套是休妻的(如果目前的胎面已经消失,其锁定将只会增加);此外,在儿童过程中,它只是单方面地超越了所有锁锁——见<条码>的摘录/准则>。
/* Reset the file list. These are recursive mutexes. */
fresetlockfiles ();
/* Reset locks in the I/O code. */
_IO_list_resetlock ();
/* Reset the lock the dynamic loader uses to protect its data. */
__rtld_lock_initialize (GL(dl_load_lock));
<代码>resetlock和lock_ initialize
功能最终称为“glibc s Internal amount of pthread_mutex_init(
,不论等待者如何,均有效重订该校正。
我认为,理论是,通过获得(收回)锁锁,它保证,任何其它read子都不会触动数据结构(至少可能造成坠毁),然后重新打开单个锁,确保资源被永久冻结。 (打破目前的read锁是安全的,因为现在没有其他的线索来争夺数据结构,而且实际上在任何功能用锁返回之前就打赢了。)
我不会百分之百地相信,这涵盖所有突发事件(特别是如果/当信号手返回时,刚刚失窃的锁定功能将试图打破锁定,内部停机功能会保护人们避免锁定太多时间!) 但看来,一个可行的计划could,将建筑在星号-信号-航道上。
Finally, even if fork is safe in
signal handlers, is it safe to fork in
a signal handler and then return from
the signal handler, or does a call to
fork in a signal handler always
necessitate a subsequent call to _exit
or one of the exec family of functions
before the signal handler returns?
我假设你再次谈论儿童进程? (如果fork(>
>_ async-signal-safe>就意味着什么时候可以返回父母!)
我没有发现其他国家(尽管我可能已经错过)的幽灵中的任何东西,但我认为,should be 是安全的——至少是安全的——因为从儿童信号手里返回并不意味着自己没有界定的行为,尽管多面过程刚刚启动这一事实可能意味着exec*(
或_exit(
)。