.
D 2010-07-06T22:42:00
J assignee vasiljevic
J cmimetype text/plain
J comment This\sbug\sis\sa\smember\sof\s"rare\ssegfaults\son\sexit"\sfamily.\sHowever\sI've\sfound\sa\sway\sto\sreproduce\sit\sreliably:\n\n#!/usr/bin/wish8.6\n#\sThe\s_wish_\sinterpreter\sis\smandatory\sfor\sreproducing\sthe\sbug\susing\sthis\sscript:\s\n#\sthe\sexample\sbelow\sdepends\son\sTk_MainEx()\sbeing\scalled.\npackage\sreq\sThread\npackage\sreq\sTk\n#\sCreate\sthread\spool\nset\stph\s[tpool::create]\n#\sPost\sa\slong-running\sjob\ntpool::post\s-nowait\s-detached\s$tph\s"after\s5000;\s\n\s\s[list\sthread::send\s-async\s[thread::id]\s{puts\s"foo\sbar,\syep?"}];"\n#\sMake\sTk/wish\sexit\searlier\sthan\sthe\sjob\sfinishes\nafter\s3000\s{destroy\s.}\n#\sAnd\sthen\sit\ssegfaults.\n\nWhat's\sgoing\son?\n1.\sOn\sinitial\s`package\srequire\sThread',\sthreadCmd.c:Init()\sis\scalled\sfor\sthe\smain\sinterpreter.\sInterps\sfor\sother\sthreads\sare\screated\swith\sthreadCmd.c:NewThread(),\sonly\sthe\smain\sone\sis\snot\s_created_\sbut\s_registered_\swith\sInit().\sNewThread()\stakes\scare\sto\sTcl_Preserve/Tcl_Release\sthe\sinterp\swhen\sappropriate,\sbut\sInit()\sdoesn't.\sPointer\sto\sthe\smain\sinterp\sis\snow\sstored\sin\stsdPtr,\sbut\sthere\sis\sno\sTcl_Preserve\scall\sto\sprevent\sits\sdestruction,\snor\sTcl_CallWhenDeleted\shandler\sto\swipe\sthe\spointer\swhen\sthe\sinterp\sis\sdestroyed.\sBAD.\n\n2.\sThread\spool\sis\screated\sand\sthe\sjob\sis\sposted,\sso\sa\sworker\sthread\sis\screated\sand\sNewThread\sis\sstarted\sin\sit.\sNo\sproblem\shere.\n\n3.\sBefore\sthe\sjob\sfinishes,\smain\swindow\sis\sdestroyed,\sand\sTk_MainEx\sis\sgoing\sto\sexit.\n\n4.\sTk_MainEx\smarks\sthe\smain\sinterp\sfor\sdeletion,\sthen\scalls\sTcl_Release\son\sit,\scausing\sits\sactual\sdeletion.\sFrom\slooking\sat\sTk_MainEx\sI\sdecided\sthat\sit\shas\sthe\sright\sto\sdo\swhat\sit\sdoes\s-\sthat's\swhy\sthis\sbug\sis\ssubmitted\sagainst\sThread\spackage,\snot\sTk.\s\n\n4.1.\sAt\sthis\spoint,\stsdPtr\sof\sthread\spackage\shas\sa\sdangling\sreference\sto\sa\scorpse\sof\smain\sinterp.\sBAD.\n\n5.\sThen\sTk_MainEx\scalls\sTcl_Exit(0),\swhich\sin\sturn\sinvokes\sapplication\sexit\shandlers.\n\n6.\sThreadPoolCmd.c:AppExitHandler()\stries\sto\sdestroy\sthe\sthread\spool\sgracefully.\sIt\scauses\sa\sworker\sthread\sto\sexit\sand\sthen\swaits\sfor\sit,\scalling\sTcl_DoOneEvent()\srepeatedly\suntil\sthere\sis\sno\sworkers.\n\n7.\sBut,\s_before_\sthe\sworker\sthread\sexits,\sit\sposts\san\sevent\sto\sthe\smain\sthread,\sasking\sit\sto\seval\s"puts..."\swithin\sits\smain\sinterp\s(that\sdoesn't\sexist).\n\n8.\sthreadCmd.c:ThreadEventProc()\sretrieves\sa\sdangling\sinterp\spointer\sfrom\smain\sthread's\stsd.\n\n9.\sWhen\sit\scomes\sto\sTcl_ResetResult(dead\sinterp),\swish\ssegfaults.\n\nA\spossible\ssolution,\snot\snessesary\sthe\sbest\sone,\sis\sto\sadd\sa\scouple\sof\slines\sinto\sthreadCmd.c:Init():\n\sTcl_Preserve(interp);\n\sTcl_CreateThreadExitHandler(Tcl_Release,\sinterp);\n\nAnother\spossible\ssolution\sis\sto\sassign\sNULL\sto\stsdPtr->interp\swhen\sinterp\sis\sdeleted\s(Tcl_CallWhenDeleted).\n
J foundin None
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter a_kovalenko
J subsystem 80.\sThread\sPackage
J title threadCmd.c:Init()\sreferences\san\sinterp\sbut\snot\spreserves\sit
J type Bug
K 3026061fffffffffffffffffffffffffffffffff
U a_kovalenko
Z 9db0034d499be38b86863fb845995bf9