Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 1d2608848223d41de4bb29ed850b731fdc1435a2
Ticket: 3608957fffffffffffffffffffffffffffffffff
Events posted by Tcl_QueueEvent linger in queue
User & Date: jenglish on 2013-03-25 08:00:07
Changes

  1. icomment:
    The idea behind write-to-pipe is: use pipe(2) to get a pair of connected file descriptors; in the event loop listen on the read end (with select, poll, kqueue, whatever), and in the signal handler write a single byte (generally the signal number) to the write end.  That will wake up the event loop, which can read the pipe to determine which signal was sent.
    
    write(2) is async-signal safe, whereas almost none of the pthread_* routines are.  That's why this approach is preferred.
    
    > I switched to Tcl_AsyncMark for my library, because apparently
    >  that command was specifically designed to handle cases like this 
    
    That may have been the original intent, but since the first thing Tcl_AsyncMark() does is lock a mutex, it can't be called from a signal handler either.
    
    > and it seems to work just fine.
    
    "seems" being the operative word here :-)  If a signal ever gets delivered while Tcl is in the middle of an AsyncInvoke or other critical section, the process will deadlock.  
    
    Also beware: async handlers are called at very precarious times; the interp can be in almost any state, you have to be very careful.  (Scheduling a callback with Tcl_QueueEvent is about the only thing you should do in an async handler).
    
    
  2. login: "jenglish"
  3. mimetype: "text/plain"
  4. username: "jenglish"