Artifact
b4df16c944bee23a8ee55df6897a32e0b2a559b886b041eb16507f3c6197ad9b:
Ticket change
[b4df16c944]
- New ticket [b3905a822661d7cc|b3905a8226] <i>Code Not Thread-Safe</i>.
by
anonymous
2021-04-12 19:42:27.
D 2021-04-12T19:42:27.059
J foundin 1.0.11
J icomment The\sextension\scrashes\swhen\sused\sin\smultiple\sthreads.\sThe\sproblem\sis\sin\sUDP_CheckProc\swhen\sit\sis\sdetermining\swhether\sit\sshould\sread\sthe\ssocket.\sIf\sthere\sare\smultiple\sthreads,\sthe\sorder\sin\swhich\sthe\sthreads\scall\sthis\sfunction\sis\snot\sdeterministic,\sso\sit\sis\spossible\sthat\sthe\swrong\sthread\swill\sread\sthe\ssocket.<br>\r\n<br>\r\nThe\ssolution\sis\sto\sverify\sthe\scorrect\sthread\sby\schanging:\r\n<pre>\s\s\s\sif\s(statePtr->packetNum\s>\s0)\s{</pre>\r\nto:<br>\r\n<pre>\s\s\s\sif\s(statePtr->packetNum\s>\s0\s&&\sstatePtr->threadId\s==\sTcl_GetCurrentThread())\s{</pre>\r\n\r\nHere\sis\sa\sscript\sthat\sdemonstrates\sthe\sproblem.\sThe\smain\sthread\sreads\sa\ssocket\sand\sa\schild\sthread\swrites\sa\ssocket:<br>\r\n<pre>\r\n\s\s\s\spackage\srequire\sudp\r\n\s\s\s\spackage\srequire\sThread\r\n\s\s\s\s\r\n\s\s\s\sproc\shandleRead\s{chan}\s{\r\n\s\s\s\s\s\s\s\sset\sdata\s[read\s$chan]\r\n\s\s\s\s\s\s\s\sputs\s"received\s[string\slength\s$data]\sbyte(s)"\r\n\s\s\s\s}\r\n\s\s\s\s\r\n\s\s\s\sset\schan\s[udp_open]\r\n\s\s\s\sset\sport\s[fconfigure\s$chan\s-myport]\r\n\s\s\s\sfileevent\s$chan\sreadable\s[list\shandleRead\s$chan]\r\n\s\s\s\s\r\n\s\s\s\sset\stid\s[::thread::create]\r\n\s\s\s\s::thread::send\s$tid\s"set\sport\s$port"\r\n\s\s\s\s::thread::send\s$tid\s{\r\n\s\s\s\s\s\s\s\spackage\srequire\sudp\r\n\s\s\s\s\s\s\s\sset\schan\s[udp_open]\r\n\s\s\s\s\s\s\s\sfconfigure\s$chan\s-remote\s[list\slocalhost\s$port]\s-buffering\snone\r\n\s\s\s\s}\r\n\s\s\s\s\r\n\s\s\s\swhile\s1\s{\r\n\s\s\s\s\s\s\s\s::thread::send\s$tid\s{puts\s-nonewline\s$chan\sA}\r\n\s\s\s\s\s\s\s\supdate\r\n\s\s\s\s}\r\n</pre>
J login anonymous
J mimetype text/html
J private_contact 1c57e67924247fd7926e89348f266c081ec57db2
J severity Critical
J status Open
J title Code\sNot\sThread-Safe
J type Code_Defect
K b3905a822661d7ccb060926e81b832198ed415b5
U anonymous
Z 9f5d525f4259609df39f1503da95807b