Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 184f572719eacae3c6b281732e1f3c317a8dd995
Ticket: 1160057fffffffffffffffffffffffffffffffff
Seg fault from usleep
User & Date: s_a_white on 2005-03-09 17:49:25
Changes

  1. assignee changed to: "andreas_kupries"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    Am trying to determine what may be going on in tcl that
    causes this code to crash.  Using a main instead of tcl
    to run the code it appears to work fine.
    
    The computer is running MandrakeLinux 10.1:
    
    kernel: 2.6.8.1-12mdksmp
    gcc: 3.4.3-1mdk
    glibc: 2.3.3-21mdk
    tcl: 8.4.5-6mdk
    
    Code:
    
    #include <stdint.h>
    #include <stdio.h>
    #include <pthread.h>
    #include <unistd.h>
    #include <tcl.h>
    
    class Message
    {
    public:
       Message();
       ~Message ();
    };
    
    Message::Message() {}
    Message::~Message () {}
    
    static void *RecallTaskEntry(void *_this)
    {
       Message m;
       usleep(2000000);
       return 0;
    }
    
    extern "C" int createThread() {
      pthread_t Recallthread;
      pthread_create(&Recallthread,NULL,RecallTaskEntry, 0);
      usleep (50000);
      pthread_cancel (Recallthread);
      pthread_join   (Recallthread, NULL);
      return 0;
    }
    
    int TclCreateThread (ClientData clientData, Tcl_Interp
    *interp,
                         int argc,CONST84 char *argv[])
    {
      createThread ();
      return TCL_OK;
    }
    
    extern "C" int Thread_Init(Tcl_Interp *interp) {
       
    Tcl_CreateCommand(interp,"createThread",TclCreateThread,
    0, 0);
        return TCL_OK;
    }
    
    extern "C" int Thread_SafeInit(Tcl_Interp *interp) {
       return (Thread_Init(interp));
    }
    
    Code is C++ compiled as a shared library and run in tcl
    via:
    
    load libThread.so
    createThread
    
    The observed beviour is a segfault which results from
    doing a pthread_cancel when the thread is in the
    usleep.  The debugger output looks a little confused
    like possible stack corruption.  However as explained
    it works ok standalone outside of tcl.
    
    Things that seem to make it work are:
    
    - Removing the Message object from the thread.
    - Removing Messages destructor.
    - As a test using sleep and pause instead of usleep
    appear to work.
    
    Any ideas on what is causing this bug?
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "s_a_white"
  9. subsystem changed to: "49. Threading"
  10. title changed to: "Seg fault from usleep"
  11. type changed to: "Bug"