Tcl package Thread source code

Artifact [6dd7409b18]
Login

Artifact 6dd7409b18e374fa9325c0d117a684a2dd896b0e04b21aa93689222cb9ae1fb6:

Ticket change [6dd7409b18] - Ticket [b5709ea906] [::thread::send -async] posting order not respected when sending to current thread status still Open with 4 other changes by adrianmedranocalvo 2018-07-31 16:22:35.
D 2018-07-31T16:22:35.500
J icomment Hello\ssebres,\r\n\r\nthere's\sdefinitely\ssome\smisunderstanding.\s\sEnglish\sis\snot\smy\smother\slanguage,\sit's\snot\sthe\sfirst\stime\sI\scause\sa\smess...\r\n\r\nI'll\stry\sto\sexplain\swith\scode.\r\n\r\nOne\simportant\spoint\sis:\sI\sdon't\scare\sabout\sthe\sorder\sof\s[after\sidle]\sevents\snor\s[after\s0]\sevents\swith\srespect\sto\s[thread::send\s-async]\sevents.\s\sI\sonly\scare\sabout\sthe\sorder\sof\s[thread::send\s-async]\sevents.\r\n\r\nPlease,\stry\sthe\sfollowing\sscript:\r\n\r\n~~~\r\npackage\srequire\sThread;\r\n\r\nset\st(main)\s[::thread::id]\r\nset\st(other)\s[::thread::create]\r\n\r\n#\sLet\st(other)\sknow\sthe\smain\sthread's\sid,\st(main).\r\n::thread::send\s$t(other)\s[list\sarray\sset\st\s[array\sget\st]]\r\n\r\n#\sAsync\sthread::send\sto\scurrent\sthread\s(the\smain\sthread).\r\n#\sI\sexpect\sthis\sscript\sto\sbe\sinserted\sat\sthe\send\sof\sthe\sthread\sevent\squeue.\r\n::thread::send\s-async\s$t(main)\s{\r\n\s\s\s\slappend\s::trace\sLOCAL-THREAD-SEND;\r\n}\r\n\r\n::thread::send\s$t(other)\s{\r\n\s\s\s\s#\sAsync\sthread::send\sto\sother\sthread\s(the\smain\sthread).\r\n\s\s\s\s#\sI\sexpect\sthis\sscript\sto\sbe\sinserted\sat\sthe\send\sof\sthe\r\n\s\s\s\s#\sthread\sevent\squeue,\safter\sthe\sone\sabove.\r\n\s\s\s\s::thread::send\s-async\s$t(main)\s{\r\n\t\s\slappend\s::trace\sREMOTE-THREAD-SEND;\r\n\s\s\s\s}\r\n}\r\n\r\nafter\s100\s{set\sforever\s1};\r\nvwait\sforever;\r\nputs\s[join\s$::trace\s"\\n"];\r\n~~~\r\n\r\nThis\sis\sthe\soutput:\r\n\r\n~~~\r\nREMOTE-THREAD-SEND\r\nLOCAL-THREAD-SEND\r\n~~~\r\n\r\nThis\sis\snot\sexpected,\sbecause\sthe\s[thread::send\s-async]\slappending\sLOCAL-THREAD-SEND\sran\sbefore\sthe\sone\slappending\sREMOTE-THREAD-SEND.\r\n\r\nWhen\sI\sremove\sthe\sfollowing\scode:\r\n\s\shttps://core.tcl-lang.org/thread/artifact?udc=1&ln=2742-2759&name=61003585d6458178&udc=1\r\n\r\nI\sobtain\sthe\sexpected\soutput:\r\n\r\n~~~\r\nLOCAL-THREAD-SEND\r\nREMOTE-THREAD-SEND\r\n~~~\r\n\r\nAre\sthere\sany\sdownsides\sin\sremoving\sthe\sfollowing\scode?\r\n\s\shttps://core.tcl-lang.org/thread/artifact?udc=1&ln=2742-2759&name=61003585d6458178&udc=1\r\n\r\n----------------------------------------\r\n\r\nI'll\snow\stry\sto\srespond\sto\syour\spoints.\r\n\r\n>\sif\syou'll\sdo\sthat,\sthe\sevent\swill\sbe\sappended\sdirectly\sinto\sthe\squeue\sof\sthe\sthread,\sso\sin\sthis\scase\sit\swill\sbe\snot\sLAST\s(as\sby\sidle)\sbut\sFIRST\sevent\s(because\stimer\sevents\scoming\slater\svia\sprocessing\sof\sevent-sources).\r\n>\r\n>\sSo\sagain,\sit\scannot\sbe\s"on\sthe\sorder\sthey\swere\sposted",\sbecause\sthey\sare\sanother\stypes\sof\sevents.\sIt\swill\sbe\snot\sbetween\syour\stimer-events,\sbut\seither\shereafter\s(like\snow)\sor\sbefore\s(if\sdirect\sappended\sto\sevent-queue).\sBut\sdefinitely\snot\sbetween.\r\n\r\nI\sthink\sthat's\swhat\sI\swant\sand\sexpect,\sthat\sthe\s[thread::send\s-async]\sis\sappended\sto\sthe\squeue\sof\sthe\sthread.\s\sI\sdon't\sexpect\sthem\sto\sbe\shandled\sbetween\sother\stypes\sof\sevents.\r\n\r\n>\sFor\sthis\scase\s"thread::send\s-async\s[thread::id]"\sshould\sbe\squasi\srewritten\sas\s"after\s0",\sand\sI'm\sdefinitely\sagainst\sthis,\sbecause\sit\sproduces\sunexpected\soverhead.\r\n\r\nI'm\salso\sagainst\sthis.\s\sIn\sfact\sthat's\sthe\sprecise\sproblem:\s"thread::send\s-async\s[thread::id]"\sis\sbeing\srewritten\sinto\s"after\sidle".\s\sSee\sthe\spart\sof\sthe\scode\swhere\sthat\shappens\s(https://core.tcl-lang.org/thread/artifact?udc=1&ln=2742-2759&name=61003585d6458178&udc=1):\r\n\r\n\s\s2742\s\s\s\s\s\s/*\r\n\s\s2743\s\s\s\s\s\s\s*\sShort\scircuit\ssends\sto\sourself.\r\n\s\s2744\s\s\s\s\s\s\s*/\r\n\s\s2745\s\s\r\n\s\s2746\s\s\s\s\s\sif\s(thrId\s==\sTcl_GetCurrentThread())\s{\r\n\s\s2747\s\s\s\s\s\s\s\s\s\sTcl_MutexUnlock(&threadMutex);\r\n\s\s2748\s\s\s\s\s\s\s\s\s\sif\s((flags\s&\sTHREAD_SEND_WAIT))\s{\r\n\s\s2749\s\s\s\s\s\s\s\s\s\s\s\s\s\sint\scode\s=\s(*send->execProc)(interp,\s(ClientData)send);\r\n\s\s2750\s\s\s\s\s\s\s\s\s\s\s\s\s\sThreadFreeProc((ClientData)send);\r\n\s\s2751\s\s\s\s\s\s\s\s\s\s\s\s\s\sreturn\scode;\r\n\s\s2752\s\s\s\s\s\s\s\s\s\s}\selse\s{\r\n\s\s2753\s\s\s\s\s\s\s\s\s\s\s\s\s\ssend->interp\s=\sinterp;\r\n\s\s2754\s\s\s\s\s\s\s\s\s\s\s\s\s\sTcl_Preserve((ClientData)send->interp);\r\n\s\s2755\s\s\s\s\s\s\s\s\s\s\s\s\s\sTcl_DoWhenIdle((Tcl_IdleProc*)ThreadIdleProc,\s(ClientData)send);\r\n\s\s2756\s\s\s\s\s\s\s\s\s\s\s\s\s\sreturn\sTCL_OK;\r\n\s\s2757\s\s\s\s\s\s\s\s\s\s}\r\n\s\s2758\s\s\s\s\s\s}\r\n\r\n>\sPossibly\sfor\smy\sanother\sevent-branch\s(that\sI\swrote\sin\stcl-core-repo),\swhere\s"after\s0"\shave\sO(1)\sby\schanging\sof\stimer-queue,\sdoes\snot\sgenerate\sextra\soverhead\sas\sregards\stime-compare\sat\sall\s(because\screates\san\simmediate\stimer-event),\setc.\r\nIf\sthis\swill\sbe\saccepted\ssometimes...\s\r\n\r\nMore\sperformant\sevent\shandling\sis\salways\swelcome...\sthank\syou\sfor\syour\sefforts,\sI\shope\sit\sgets\smerged\ssoon.
J login adrianmedranocalvo
J mimetype text/plain
J username [email protected]
K b5709ea9060d17f58ba48110351c964b3408e362
U adrianmedranocalvo
Z 6ea0d9c1d6097f0d812ec5ab2467d4ee