Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0289ecb1e11210028a9252054c19e58834a13ca6
Ticket: 1437595fffffffffffffffffffffffffffffffff
WinSock cores/hangs on thread or app exit
User & Date: vasiljevic on 2006-03-01 04:19:39
Changes

  1. icomment:
    Logged In: YES 
    user_id=95086
    
    OK. Easy.  But you will have to follow me...
    
    If you open a socket, don't close it and exit the thread
    (or the application,  this will eventually come to
    
      Tcl_FinalizeThread()
    
    The Tcl_FinalizeThread will pull thread-exit handlers
    one by one. One of them will be the handler to tear down
    the socket subsystem.
    This thread-exit handler will tear-down the socket thread and
    all the sync primitieves for the synchronization. After that 
    no calls into this subsystem should be performed.
    But....
    After that, the TclFinalizeIOSubsystem() is called.
    The TclFinalizeIOSubsystem walks the list of opened channels,
    founds one still opened and tries to close it (line 254 in generic/tclIO.c).
    The Tcl_Close will invoke CloseChannel and this will call Tcl_CutChannel.
    The Tcl_CutChannel will, as the last step of operation, call
    ThreadActionProc with  TCL_CHANNEL_THREAD_REMOVE.
    Understand? Now, the ThreadActionProc will result in 
    TcpThreadActionprroc (line 2689 win/tclWinChan.c) and will start 
    using tsdPtr->socketListLock, will attemt to SendMessage to 
    window owned by the SocketThread which already is exited 
    and so on and so on... 
    
    Is this now little bit more clear?
    
    Concerning lazy init/teardown of socket subsystem, the answer is: yes.
    If this is in place, then this will be better and more logical. The first
    channel/socket inits, the last closing tears down the subsystem.
    This is how I'd do the thing If I had designed it. But I was not so I
    had to at least rectify the obviously broken current implementation.
    
    
    
    
  2. login: "vasiljevic"
  3. mimetype: "text/plain"
  4. username: "vasiljevic"