.
D 2008-10-16T16:46:59
J assignee nijtmans
J cmimetype text/plain
J comment I\swant\sto\swrite\san\sapplication\sthat\sis\sable\sto\sstart\sand\sstop\sa\stcl\sinterpreter\son\sdemand.\nBut\sthere\sseems\sto\sbe\sa\sproblem\s\s-\swhen\scalling\sTcl_FinalizeThread\sthe\sapplication\scrashes\s!\n\nTcl_FinalizeThread()\sdoes\snot\saccept\sany\sparameters,\sso\sif\sI\swant\sto\sfinalize\sthe\sTcl\sthread\sI\shave\sto\scall\sit\sfrom\sthe\sTcl\sthread\s(using\sthe\sevent\squeue\swith\sTcl_ThreadQueueEvent).\nWhen\sdoing\sthis\sa\scrash\soccurs.\n\nTcl_FinalizeThread\scleans\sup\smany\sdata\sstructures\s(queueMutex,...).\sBut\sthis\sdata\ssttructures\sare\sneccessary\sto\sexecute\sthe\sfollowing\scode\ssection\sin\sTcl_ServiceEvent.\sBecause\sthese\sdata\sstructures\shave\sbeen\sfreed,\sTcl\stries\sto\saccess\sa\sptr\s0xdddddddd.\n\nI\sdo\snot\sthink\sthat\sthere\sis\sa\svalid\scontext\sto\scall\sTcl_FinalizeThread,\sso\splease\sfix\sthe\sbug.\n\n\n1.\scallstack\n\n\stcl84.dll!Tcl_MutexLock(Tcl_Mutex_\s*\s*\smutexPtr=0x03922cac)\s\sLine\s500\s+\s0xc\sbytesC\n\stcl84.dll!Tcl_ServiceEvent(int\sflags=0xfffffffd)\s\sLine\s641\s+\s0xc\sbytesC\n>tcl84.dll!Tcl_DoOneEvent(int\sflags=0xfffffffd)\s\sLine\s945\s+\s0x9\sbytesC\n\sHmiTclSupport.dll!TclThreadMainLoop()\s\sLine\s735\s+\s0x1a\sbytesC++\n\stcl84.dll!Tcl_Main(int\sargc=0xffffffff,\schar\s*\s*\sargv=0x03fa15e0,\sint\s(Tcl_Interp\s*)*\sappInitProc=0x03f984d0)\s\sLine\s444\s+\s0x8\sbytesC\n\n\n2.\sthe\slocation\sthe\serror\soccurs\n\nint\nTcl_ServiceEvent(flags)\n\s\s\s\sint\sflags;/*\sIndicates\swhat\sevents\sshould\sbe\sprocessed.\n\s*\sMay\sbe\sany\scombination\sof\sTCL_WINDOW_EVENTS\n\s*\sTCL_FILE_EVENTS,\sTCL_TIMER_EVENTS,\sor\sother\n\s*\sflags\sdefined\selsewhere.\s\sEvents\snot\n\s*\smatching\sthis\swill\sbe\sskipped\sfor\sprocessing\n\s*\slater.\s*/\n{\n\s\s\s\sTcl_Event\s*evPtr,\s*prevPtr;\n\s\s\s\sTcl_EventProc\s*proc;\n\s\s\s\sint\sresult;\n\s\s\s\sThreadSpecificData\s*tsdPtr\s=\sTCL_TSD_INIT(&dataKey);\n\n\s\s\s\s/*\n\s\s\s\s\s*\sAsynchronous\sevent\shandlers\sare\sconsidered\sto\sbe\sthe\shighest\n\s\s\s\s\s*\spriority\sevents,\sand\sso\smust\sbe\sinvoked\sbefore\swe\sprocess\sevents\n\s\s\s\s\s*\son\sthe\sevent\squeue.\n\s\s\s\s\s*/\n\s\s\s\s\n\s\s\s\sif\s(Tcl_AsyncReady())\s{\n(void)\sTcl_AsyncInvoke((Tcl_Interp\s*)\sNULL,\s0);\nreturn\s1;\n\s\s\s\s}\n\n\s\s\s\s/*\n\s\s\s\s\s*\sNo\sevent\sflags\sis\sequivalent\sto\sTCL_ALL_EVENTS.\n\s\s\s\s\s*/\n\s\s\s\s\n\s\s\s\sif\s((flags\s&\sTCL_ALL_EVENTS)\s==\s0)\s{\nflags\s|=\sTCL_ALL_EVENTS;\n\s\s\s\s}\n\n\s\s\s\s/*\n\s\s\s\s\s*\sLoop\sthrough\sall\sthe\sevents\sin\sthe\squeue\suntil\swe\sfind\sone\n\s\s\s\s\s*\sthat\scan\sactually\sbe\shandled.\n\s\s\s\s\s*/\n\n\s\s\s\sTcl_MutexLock(&(tsdPtr->queueMutex));\n\s\s\s\sfor\s(evPtr\s=\stsdPtr->firstEventPtr;\sevPtr\s!=\sNULL;\n\sevPtr\s=\sevPtr->nextPtr)\s{\n/*\n\s*\sCall\sthe\shandler\sfor\sthe\sevent.\s\sIf\sit\sactually\shandles\sthe\n\s*\sevent\sthen\sfree\sthe\sstorage\sfor\sthe\sevent.\s\sThere\sare\stwo\n\s*\stricky\sthings\shere,\sboth\sstemming\sfrom\sthe\sfact\sthat\sthe\sevent\n\s*\scode\smay\sbe\sre-entered\swhile\sservicing\sthe\sevent:\n\s*\n\s*\s1.\sSet\sthe\s"proc"\sfield\sto\sNULL.\s\sThis\sis\sa\ssignal\sto\sourselves\n\s*\s\s\s\sthat\swe\sshouldn't\sreexecute\sthe\shandler\sif\sthe\sevent\sloop\n\s*\s\s\s\sis\sre-entered.\n\s*\s2.\sWhen\sfreeing\sthe\sevent,\smust\ssearch\sthe\squeue\sagain\sfrom\sthe\n\s*\s\s\s\sfront\sto\sfind\sit.\s\sThis\sis\sbecause\sthe\sevent\squeue\scould\n\s*\s\s\s\schange\salmost\sarbitrarily\swhile\shandling\sthe\sevent,\sso\swe\n\s*\s\s\s\scan't\sdepend\son\spointers\sfound\snow\sstill\sbeing\svalid\swhen\n\s*\s\s\s\sthe\shandler\sreturns.\n\s*/\n\nproc\s=\sevPtr->proc;\nif\s(proc\s==\sNULL)\s{\n\s\s\s\scontinue;\n}\nevPtr->proc\s=\sNULL;\n\n/*\n\s*\sRelease\sthe\slock\sbefore\scalling\sthe\sevent\sprocedure.\s\sThis\n\s*\sallows\sother\sthreads\sto\spost\sevents\sif\swe\senter\sa\srecursive\n\s*\sevent\sloop\sin\sthis\sthread.\s\sNote\sthat\swe\sare\smaking\sthe\sassumption\n\s*\sthat\sif\sthe\sproc\sreturns\s0,\sthe\sevent\sis\sstill\sin\sthe\slist.\n\s*/\n\nTcl_MutexUnlock(&(tsdPtr->queueMutex));\nresult\s=\s(*proc)(evPtr,\sflags);\n->\scrash::\n->\scrash::\n->\scrash::\n->\scrash::\n->\scrash::\nTcl_MutexLock(&(tsdPtr->queueMutex));\n->\scrash::\n->\scrash::\n->\scrash::\n->\scrash::\n\n\n\nif\s(result)\s{\n\s\s\s\s/*\n\s\s\s\s\s*\sThe\sevent\swas\sprocessed,\sso\sremove\sit\sfrom\sthe\squeue.\n\s\s\s\s\s*/\n\n\n\n
J foundin obsolete:\s8.4.19
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 02.\sEvent\sLoops
J title Crash\swhen\scalling\sTcl_FinalizeThread()
J type Bug
K 2172279fffffffffffffffffffffffffffffffff
U nobody
Z ae7846d31f4ee9c81e7921f631119cc3