[ CnUnix ] in KIDS ±Û ¾´ ÀÌ(By): wooyou (Ä¡Áîorºü´Ù) ³¯ Â¥ (Date): 2002³â 5¿ù 17ÀÏ ±Ý¿äÀÏ ¿ÀÈÄ 10½Ã 06ºÐ 25ÃÊ Á¦ ¸ñ(Title): [q]pthread¾È¿¡¼­ fork¿¡¼­ deadlock¹ß»ý pthreadÇÁ·Î±×·¥À» Çϳª ÀÛ¼ºÇߴµ¥, ±×Áß ÇÑ thread¿¡¼­ fork¸¦ ÇؾßÇÒÀÏÀÌ ÀÖ½À´Ï´Ù. ±×·¯³ª °¡²û¾¿ forkÇÏ´Ù°¡ ÇÁ·Î±×·¥ÀÌ ²Ä¦ÇÏÁö ¾Ê¾Æ¼­ gdb·Î »ìÆ캸´Ï deadlockÀÌ ¹ß»ýÇÏ´Â °Í °°½À´Ï´Ù. ÇÁ·Î±×·¥¾È¿¡¼­ Á÷Á¢ mutex¸¦ »ç¿ëÇÏÁö´Â ¾Ê´Âµ¥, ½Ã½ºÅÛ(?)¿¡¼­ pthread_atfork °¡ °á°úÀûÀ¸·Î mutex¸¦ °É¸é¼­ À̶§ deadlockÀÌ ¹ß»ýÇÏ´Â °Í °°½À´Ï´Ù. ¾Æ·¡ÀÇ °á°ú¸¦ º¸¸é 7¹ø° frame¿¡¼­ fork¸¦ È£ÃâÇϸ鼭 0~5±îÁö ½Ã½ºÅÛÀÌ ÀÚµ¿À¸·Î fork¸¦ ¼öÇàÇϱâ À§Çؼ­ ¿Ã¶ó°¡´Â stackÀÎ°Í °°Àºµ¥, ¿©±â¼­ deadlockÀÌ °É¸®´Ï ²Ä¦À» ¸øÇÏ°Ú½À´Ï´Ù. Ȥ½Ã ÀÌ¿¡ ´ëÇؼ­ ÁÁÀº ÀÇ°ß ÀÖÀ¸½Ã¸é ºÎŹµå¸³´Ï´Ù. (gdb) bt #0 0xc020f8a0 in __ksleep () from /usr/lib/libc.2 #1 0xc003da4c in pthread_mutex_lock () from /usr/lib/libpthread.1 #2 0xc02235a4 in __thread_mutex_lock () from /usr/lib/libc.2 #3 0xc0220ea8 in sendpath64 () from /usr/lib/libc.2 #4 0xc003e0f8 in pthread_atfork () from /usr/lib/libpthread.1 #5 0xc003e450 in __pthread_fork () from /usr/lib/libpthread.1 #6 0xc021c644 in fork () from /usr/lib/libc.2 #7 0x11bf0 in CProcess::Execute (this=0x7f7f0704, strObj=0x7f7f083c "/home/iux/BIN/TxxMain", strArgv=0x7f7f0a3c "TxxMain Tx01 ") at CProcess.cpp:55 #8 0x7d38 in CPms::execute (this=0x7f7f0648, com=@0x7f7f0774) at CPms.cpp:344 #9 0x7620 in CPms::start (this=0x7f7f0648) at CPms.cpp:203 #10 0xb9c4 in main (argc=2, argv=0x7f7f051c) at PmsMain.cpp:118 [ 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. [ CnUnix ] in KIDS ±Û ¾´ ÀÌ(By): terzeron (microkid) ³¯ Â¥ (Date): 2002³â 5¿ù 17ÀÏ ±Ý¿äÀÏ ¿ÀÈÄ 11½Ã 59ºÐ 36ÃÊ Á¦ ¸ñ(Title): Re: [q]pthread¾È¿¡¼­ fork¿¡¼­ deadlock¹ß alita´Ô²²¼­ ÀοëÇϽŠman page¿¡µµ ºñ½ÁÇÑ ³»¿ëÀÌ ³ª¿À´Âµ¥, ±»ÀÌ mutex lockÀ» °É¾ú´Ù Ç®¾ú´Ù ÇÒ ÇÊ¿ä´Â ¾øÀ» °Í °°°í µÎ¹ø° ¹æ¹ýÀ» ÀÀ¿ëÇؼ­ pthread_atfork¸¦ fork¾Õ¿¡ »ç¿ëÇÏ°í mutex¸¦ ¾È ¾²½Å´Ù´Ï mutex°ü·Ã ÀÛ¾÷À» ¾Æ¿¹ ÇÏÁö ¾Ê´Â °Íµµ ÅëÇÒ µí ½Í½À´Ï´Ù. ´Ù¸¸ mutex¸¦ ¾²¼Å¾ß ÇÑ´Ù¸é ù¹ø° Çڵ鷯 prepare¿¡¼­ Àá±ñ °É¾ú´Ù°¡ atforkÀÌÈÄ¿¡ parentÇÏ°í child¿¡¼­ Ç®¾îÁÖ´Â °úÁ¤À» ÇÇÇÒ ¼ö°¡ ¾ø°Ú³×¿ä. ¾Æ´Ï¸é µÎ¹ø° ¹æ¹ýó·³ atfork ÀÌÈÄ·Î µ¿±âÈ­ÀÛ¾÷À» ¹Ì·ï³õÀ¸½Ã´ø°¡¿ä. deadlockÀÌ °É¸®´Â ¿øÀÎÀº Ȥ½Ã fork(/execµµ?)¸¦ µÎ ¾²·¹µå°¡ µ¿½Ã¿¡ ¼öÇàÇؼ­ ±×·± °Ç ¾Æ´Õ´Ï±î? PS Àúµµ semaphore°¡ deadlockÀÌ °É¸®´Âµ¥ ÀÌ°Å Âü ȯÀåÇÒ ³ë¸©ÀÔ´Ï´Ù. °É¸± °÷ÀÌ ¾ø¾î¼­ ¸»ÀÌÁÒ. °Ô´Ù°¡ ¸Å¹ø °É¸®´Â °Ô ¾Æ´Ï°í cgi·Î ¼öÇàµÇ´Â daemonÀÌ¶ó¼­ trace¸¦ ÇÒ ¼öµµ ¾ø°í ¸»ÀÌÁÒ. -_-;; [ CnUnix ] in KIDS ±Û ¾´ ÀÌ(By): wooyou (Ä¡Áîorºü´Ù) ³¯ Â¥ (Date): 2002³â 5¿ù 18ÀÏ Åä¿äÀÏ ¿ÀÀü 12½Ã 46ºÐ 20ÃÊ Á¦ ¸ñ(Title): Re: [q]pthread¾È¿¡¼­ fork¿¡¼­ deadlock¹ß ¿ì¼± platformÀº HPUXÀ̸ç, 1°³ÀÇ ÇÁ·Î¼¼½º¿¡ 3°³ÀÇ thread°¡ ÀÖÀ¸¸ç °¢ thread´Â °¢°¢ ´Ù¸¥ ¿ªÇÒÀ» ¼öÇàÇÕ´Ï´Ù. ±×Áß ´Ü ÇϳªÀÇ ÇÁ·Î¼¼½º°¡ fork¸¦ ÅëÇؼ­ child process´Â »ý¼ºÇÕ´Ï´Ù. ½ÇÁ¦ Á¦°¡ ÄÚµùÇϱâ·Î´Â fork()¼öÇàÈÄ child process¿¡¼­ ¹Ù·Î execÀ» ¼öÇàÇϴµ¥, ¹®Á¦´Â fork()¿¡¼­ ´õÀÌ»ó ³Ñ¾î°¡Áö ¾Ê°í gdb·Î º¸´Ï fork()¸¦ ¼öÇàÇÒ¶§ threaded programÀÇ °æ¿ì´Â C compiler(?)°¡ pthread_atfork()¸¦ ÀÚµ¿À¸·Î ¼öÇàÇÏ°Ô ÇÏ¸ç ±× ³»ºÎ¿¡¼­ mutex±îÁö »ç¿ëÇÏ´Â°Í °°½À´Ï´Ù. Á¦°¡ »ç¿ëÇÑ mutex¶ó¸é ¾È¾²µµ·Ï °í¹ÎÀÌ¶óµµ Çغ¸°Ú´Âµ¥, ÀÌÂÊÀº ¼Ò½ºµµ ¾ø°í, ²À ÇؾßÇÑ´Ù¸é assembly·Î ¹Ù²ã¼­ ÇϳªÇϳª ã¾ÆºÁ¾ß ÇÏ´Â°Í °°Àºµ¥... ±×·¯±â´Â ³Ñ ±×·¸°í... ÇÏ¿©Æ° °í¹ÎÀÔ´Ï´Ù.. [ CnUnix ] in KIDS ±Û ¾´ ÀÌ(By): terzeron (microkid) ³¯ Â¥ (Date): 2002³â 5¿ù 18ÀÏ Åä¿äÀÏ ¿ÀÀü 10½Ã 10ºÐ 09ÃÊ Á¦ ¸ñ(Title): Re: [q]pthread¾È¿¡¼­ fork¿¡¼­ deadlock¹ß ±×·¯´Ï±î ¸í½ÃÀûÀ¸·Î atfork¸¦ È£ÃâÇÏ¿© ±× Çڵ鷯¿¡¼­ unlockÀ» ¼öÇàÇÏ´Â °ÍÀº ¾î¶³±î¿ä? Á¤¼®´ë·Î¶ó¸é prepare¿¡¼­ lockÇÏ°í parent¿Í child¿¡¼­ unlockÀ» Çؾ߰ÚÁö¸¸, ²Ä¼ö(²Ç¼ö?)¸¦ ½á¼­ prepare¿¡¼­ Ȥ½Ã °É·ÁÀÖÀ»Áöµµ ¸ð¸£´Â mutex lockÀ» Ç®°í°¡ÀÚ´Â °ÅÁÒ. unlockÀ̳ª initÀ» ¼öÇàÇÏ¸é µÉ °Íµµ °°½À´Ï´Ù¸¸... Á¦°¡ ¾µ ¼ö ÀÖ´Â solarisȯ°æ¿¡¼­´Â ºñ½ÁÇÑ ½Ã³ª¸®¿À¿¡¼­ fork°¡ Àß µË´Ï´Ù. atfork¾øÀ̵µ¿ä. ÀÌ ³ðÀÇ pthread°¡ ½Ã½ºÅÛ¸¶´Ù ÁË´Ù ´Ù¸£°í ƯÁ¤ ÀÛ¾÷ (½ºÄÉÁ층 °°Àº)¿¡¼­´Â ½Ã½ºÅÛÀ» Ÿ´Â ¹ö±×°¡ Á¾Á¾ À־ Àü¿¡ dalgong´Ô²²¼­ ÁöÀûÇϽŠ´ë·Î ȣȯ¼ºÀ» ¹Ï°í ¾µ¸¸ÇÑ °ÍÀº ¸ø µÇ´Â °Í °°´õ±º¿ä. [ CnUnix ] in KIDS ±Û ¾´ ÀÌ(By): alita () ³¯ Â¥ (Date): 2002³â 5¿ù 18ÀÏ Åä¿äÀÏ ¿ÀÀü 10½Ã 35ºÐ 49ÃÊ Á¦ ¸ñ(Title): Re: [q]pthread¾È¿¡¼­ fork¿¡¼­ deadlock¹ß thread Çϳª¸¸ ¶ç¿î »óÅ¿¡¼­ fork¸¦ Çصµ ±×·±Áö Å×½ºÆ®¸¦ Çغ¸´Â°Ô ÁÁÀ» °Í °°½À´Ï´Ù. :) solaris¶û linux¿¡¼­´Â threadµé call stackÀ» pstackÀ̶ó´Â °É·Î run time¿¡ º¼ ¼ö Àִµ¥¿ä, HPµµ ÀÖ³ª¿ä? linuxÀÇ pstackÀº portableÇÏÁö ¾ÊÀº°É·Î ¾Ë¾Æ¼­... @ Linux¿¡¼­ pthread¸¦ ½á¼­ ȣȯ¼ºÀº ÀüÇô °í·Á¸¦ ¾ÈÇϱä ÇßÁö¸¸¼­µµ ÃÖ´ëÇÑ ±âº»ÀûÀÎ lock/unlock¸¸ ¾²·Á´Â ³ë·ÂÀ» -_-a @@GNUÀÇ Pth¶ó´Â°Å ½áº¸½Å ºÐ ÀÖ³ª¿ä? Linux¿¡¼­ pthread¸¦ Pth¿¡ wrapper ¾º¿ì´Â ÇüÅ·Π¹Ù²Ü·Á´Â °Å °°´øµ¥. ²Ù¸®ÇÑ LinuxThread -_-; [ CnUnix ] in KIDS ±Û ¾´ ÀÌ(By): terzeron (microkid) ³¯ Â¥ (Date): 2002³â 5¿ù 18ÀÏ Åä¿äÀÏ ¿ÀÀü 10½Ã 47ºÐ 12ÃÊ Á¦ ¸ñ(Title): Re: [q]pthread¾È¿¡¼­ fork¿¡¼­ deadlock¹ß ÇÏÇÏ, BSDµµ ²Ù¸®ÇØ¿ä. Ä¿³Î¿¡ ¾²·¹µå Ç® Áö±ÝÀº ¸ð¸£°Ú´Âµ¥ ¿¹Àü¿¡´Â ¾È µé¾î°¡ ÀÖ¾ú°Åµç¿ä. [ CnUnix ] in KIDS ±Û ¾´ ÀÌ(By): swhan (foo bar) ³¯ Â¥ (Date): 2002³â 5¿ù 18ÀÏ Åä¿äÀÏ ¿ÀÀü 11½Ã 20ºÐ 57ÃÊ Á¦ ¸ñ(Title): Re: [q]pthread¾È¿¡¼­ fork¿¡¼­ deadlock¹ß ²Ç¼ö·Î ±×³É system() callÀ» »ç¿ëÇغ¸¼¼¿ä. shell script³ª µîµî¿¡¼­ fork¸¦ ÇÔ ´õ Çϵµ·Ï ÇϽðí..