CnUnix

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ CnUnix ] in KIDS
글 쓴 이(By): alita ()
날 짜 (Date): 2002년 5월 17일 금요일 오후 11시 29분 11초
제 목(Title): Re: [q]pthread안에서 fork에서 deadlock발



 pthread_atfork 는 thread에서 fork를 사용하기 위해서 parent와
 child에 fork 전후의 handler를 등록해 주는 함수입니다.
 이게 fork 안에서 자동으로 불리는거 같은데 신기하네요 *_*
 linux의 pthread_atfork의 man page 내용입니다. 관련이 없으려나...

 To  understand  the  purpose  of  pthread_atfork,  recall that fork(2) 
 duplicates the whole memory space, including mutexes in their current 
 locking state, but only the calling thread: other threads are not running  
 in  the  child  process. Thus, if a mutex is locked by a thread other than
 the thread calling fork, that mutex will remain locked forever in the child 
 process, possibly blocking the execution of the  child process.  To  avoid  
 this, install handlers with pthread_atfork as follows: the prepare handler 
 locks the global mutexes (in locking order), and the parent and child 
 handlers  unlock  them  (in  reverse  order). Alternatively, prepare and 
 parent can be set to NULL and child to a function that calls 
 pthread_mutex_init on the global mutexes.

[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.