Menu

#12 TCL UDP Problem with multi-threaded scripts on windows (NT).

v1.x
open
tcludp (16)
5
2004-11-23
2004-08-09
No

Problems:
[1] Tcl udp package does not receive any data.
[2] Tcl udp package seems to de-stabilize things, as the
following happens.
(a) keep getting crash (read some junk memory),
(b) panic "Tcl_SetIntObj called with shared object"
(c) panic when stack size check fails(??)

Some analysis:
Problem [1] was becuase SocketThread was getting
blocked on the following line,

WaitForSingleObject(statePtr->pkgState->waitForSockRe
ad, INFINITE);

Socket thread was waiting for the client thread to read
the socket, while the client thread just closed the
socket. Hence SocketThread never received any
SetEvent it was expecting.

Some thoughts:
It seems to me that event object 'sockListLock' was
being used as a lock on global list sockList. I thought
Tcl_MutexLock & Tcl_MutexUnlock can be used over
here? Also, doesn't SetEvent release all threads that are
waiting for the event to be signalled.

[From MSDN:
"Any number of waiting threads, or threads that
subsequently begin wait operations for the specified
event object by calling one of the wait functions, can be
released while the object's state is signaled."
]

In multi-threaded scripts, multiple threads could be
waiting for the signal on the event object. When it is
signalled, all of them would be released, in which case
more than one thread would potentially enter the critical
section (section accessing the global list).

When I replaced this WaitForSingleObject with Tcl Mutex,
Problem [1] was cured. But when I ran (my) tests for
more than 10 runs TCL still crashed. No Idea why :(.

I have ran my tests disabling UDP for more than 200 runs
without any issue. So the problem does seem to be
somewhere hidden within udp module. Again all my tests
ran fine on unix/solaris with udp module enabled (crashed
on linux only twise in > 500 runs).
*****************************************
OS: WinNT
Machine: Intel Pentium-4
Compilation using: MinGW.
TCL Version: 8.4.7
Additional packages loaded:
a) Pre-compiled Itcl 3.3 for windows
b) Thread 2.5.1
c) Tcllib 1.6.
*****************************************

Discussion

  • Sachin Shenoy

    Sachin Shenoy - 2004-08-09

    Uses Tcl_Mutex. Problem [1] is solved with this.

     
  • Sachin Shenoy

    Sachin Shenoy - 2004-08-11

    Logged In: YES
    user_id=1100168

    Was able to fix all above mentioned problem,
    1. Used Tcl_ThreadQueueEvent, from the SocketThread, to
    post events on to the client threads.
    2. Client threads no more registers Event Source. This is not
    required as the SocketThread posts events directly into its
    queue.
    3. Take care of stale events (events that gets serviced once
    the socket is closed).

     
  • Sachin Shenoy

    Sachin Shenoy - 2004-08-11

    With win fix, (might have broken unix code).

     
  • Sachin Shenoy

    Sachin Shenoy - 2004-08-11

    Logged In: YES
    user_id=1100168

    attaching udp_tcl.h for the Win fix.

     
  • Sachin Shenoy

    Sachin Shenoy - 2004-08-11

    header file for win fix.

     
  • Pat Thoyts

    Pat Thoyts - 2004-11-23
    • labels: --> tcludp
    • milestone: --> v1.x
    • assigned_to: nobody --> patthoyts
     

Log in to post a comment.