Tcl package Thread source code

Artifact [a9b4e19a36]
Login

Artifact a9b4e19a36f9b7a938549de45776b33dac4cadc0bf99763924f2d02879a6d4bf:

Ticket change [a9b4e19a36] - New ticket [b5709ea906] [::thread::send -async] posting order not respected when sending to current thread. by adrianmedranocalvo 2018-07-31 11:27:59.
D 2018-07-31T11:27:59.891
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment if\s{0}\s{\r\nWhen\sthe\starget\sthread\sof\s[::thread::send\s-async]\sis\sthe\scurrent\sthread,\sthe\r\nasync\sscript\sis\snot\sevaluated\sin\sorder\swith\srespect\sto\sother\s[::thread::send\r\n-async]\sscripts.\r\n\r\nLet's\scall\sa\s[::thread::send\s-async]\sinvoked\sfrom\sthe\scurrent\sthread\sand\r\ndirected\sto\sthe\scurrent\sthread\sa\slocal\s[::thread::send\s-async],\sand\sa\r\n[::thread::send\s-async]\sinvoked\sfrom\sany\sother\sthread\sand\sdirected\sto\sthe\sformer\r\nthread\sa\sremote\s[::thread::send\s-async].\r\n\r\nCurrent\sbehaviour\sis\sthat\sall\sremote\s[::thread::send\s-async]\sscripts\swill\sbe\r\nevaluated\sbefore\sany\slocal\s[::thread::send\s-asinc]\sscripts\sare,\seven\sin\sthe\scase\r\nwhere\sthe\slocal\sscripts\shave\sbeen\sposted\sbefore\sthe\sremote\sones.\s\sSee\sthe\sscript\r\nbelow\sfor\sa\sconcise\sexample.\r\n\r\nIntuitively,\s[::thread::send\s-async]\sscripts\sshould\sbe\squeued\sand\sevaluated\sin\r\nthe\sorder\sthey\swere\sadded\sto\sthe\squeue\s(that\sis,\sexcept\sif\sthe\s-head\sargument\r\nwas\sgiven).\r\n\r\nThe\sscript\sbelow\sdemostrates\sthis\sissue.\s\sWe\sappend\sto\sa\sglobal\svariable\sin\r\nthe\smain\sthread\sin\sfour\sdifferent\sways,\sin\sorder:\r\n-\sAn\safter\s0\sscript\r\n-\sAn\safter\sidle\sscript\r\n-\sA\slocal\s[thread::send\s-async]\r\n-\sA\sremote\s[thread::send\s-async]\r\n-\sAnother\safter\s0\sscript\r\n-\sAnother\safter\sidle\sscript\r\n\r\nThe\sprinted\strace\sof\sthe\sscript\sis\sreproduced\sbelow.\s\sContrary\sto\sthe\sposting\r\norder,\sthe\sremote\s[thread::send\s-async]\sis\sevaluated\sbefore\sthe\slocal\r\n[thread::send\s-async].\r\n\r\n~~~\r\nREMOTE-THREAD-SEND\r\nAFTER0-BEG\r\nAFTER0-END\r\nIDLE-BEG\r\nLOCAL-THREAD-SEND\r\nIDLE-END\r\n~~~\r\n\r\nWithout\sknowing\sthe\sdetails\sof\sthe\sThread\spackage,\sone\swould\sexpect\sthe\slocal\r\nand\sremote\s[thread::send\s-async]\sto\sbe\sevaluated\sin\sthe\sorder\sthey\swere\r\nposted.\s\sInstead,\sthe\sremote\s[thread::send\s-async]\sare\sinvariably\sevaluated\r\nbefore\sthe\slocal\sones;\sand\sthe\slocal\sones\sare\sevaluated\sas\s[after\sidle]\scommands.\r\n\r\nThe\scause\sfor\sthis\sbehaviour\sis\san\soptimization\sin\sthreadCmd.c,\scommented\sas\r\n"Short\scircuit\ssends\sto\sourself",\swhere\slocal\s[thread::send\s-async]\sare\r\nconverted\sto\s[after\sidle],\simplying\sthat\sa\sdifferent\squeue\sis\sused\sfor\slocal\r\n[thread::send\s-async]\sevents\sas\soposed\sto\sremote\s[thread::send\s-async]\sevents.\r\n\r\nHow\simportant\sis\sthis\soptimization?\s\sI\scan't\ssee\smuch\sperformance\sbeing\slost\sif\r\nwe\swould\sdisable\sthe\soptimization\sand\swould\slet\slocal\s[::thread::send\s-async]\sbe\r\nadded\sto\sthe\squeue\salong\swith\sall\sothers.\s\sThe\sbenefit\sfrom\sthis\schange\swould\sbe\r\na\smore\sconsistent\sbehaviour.\r\n\s\s\s\s\r\nThe\sunderlying\suse-case\sis\sa\sserver\swith\sconnection-specific\sthreads.\s\sThe\r\nconnection-specific\sthread\suses\slocal\s[thread::send\s-async]\sin\sorder\sto\sdelay\r\nthe\sflushing\sof\sresponses,\sso\sthat\sthe\sapplication's\slocks\sare\sgrabbed\sfor\sa\r\nminimum\samount\sof\stime.\s\sOther\sthreads\suse\sremote\s[thread::send\s-async]\sto\sthe\r\nconnection\sthread\sin\sorder\sto\ssend\smessages\sthrough\sthe\sconnection.\s\sThe\r\noptimization\sabove\sdifficults\sensuring\sthe\sorder\sthe\sresponses\sare\sflushed.\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\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\nafter\s0\s{lappend\s::trace\sAFTER0-BEG;}\r\nafter\sidle\s{lappend\s::trace\sIDLE-BEG;}\r\n\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::thread::send\s$t(other)\s{\r\n\s\s\s\s::thread::send\s-async\s$t(main)\s{\r\n\tlappend\s::trace\sREMOTE-THREAD-SEND;\r\n\s\s\s\s}\r\n}\r\n\r\nafter\s0\s{lappend\s::trace\sAFTER0-END;}\r\nafter\sidle\s{lappend\s::trace\sIDLE-END;}\r\n\r\nafter\s100\s{set\sforever\snow};\r\nvwait\sforever;\r\nputs\s[join\s$::trace\s"\\n"];\r\n\r\n#\s~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
J foundin 2.8.0
J is_private 0
J login adrianmedranocalvo
J priority 5\sMedium
J private_contact 219192cc5b7de6cef9c96726d1feb29d0382f2dc
J resolution None
J severity Important
J status Open
J submitter adrianmedranocalvo
J subsystem 80.\sThread\sPackage
J title [::thread::send\s-async]\sposting\sorder\snot\srespected\swhen\ssending\sto\scurrent\sthread
J type Bug
K b5709ea9060d17f58ba48110351c964b3408e362
U adrianmedranocalvo
Z c1a9b6ae9eb6eb510c0f3c5ac0047b63