Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 7a0970152bfd0fe4ee07d8fd89f18e1e542d16eb
Ticket: f4f44174e4c88a9132b19bcc4b68346a1d229fe1
protect notifier against signals
User & Date: aspect on 2017-01-05 06:09:26
Changes

  1. icomment:
    Just pushed a small update:  after running for some 40 hours it paniced with EAGAIN from write().  Totally expected, and should not be a panic situation.
    
    This does underline the limits of this approach though:
    
    
    #1 - eventually (under abnormally high Tcl_AsyncMark load) - and at a time we have little or no control over - the pipe will fill and we'll start dropping events.  That's not bad - it's the sort of constraint signal handlers have to deal with - but it's one pipe serving every thread, and we have no way to discard events that are in the buffer so a high-priority alert to thread A could be starved by low-priority alerts to thread B.  Not the best, even for a pathological scenario.
    
    The way the original scheme degraded was actually very nice:  events would be lost if they arrived while their handler was running, high-priority events would always get to the head of the queue (without pre-empting other handlers) and cross-thread contention was .. broken by misusing a mutex, but theoretically fairly good :).
    
    
    #2 - Windows.  According to MSDN, CreatePipe()s are synchronous "rendezvous" pipes:  writes block until a read occurs.  Also, I'm not really sure what the best interpretation of "signal handler" is on Windows but [https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx] says POSIX-style sighandlers can't use "low-level or stdio.h i/o" or system calls.
    
    An actual Windows expert's opinion on what limits AsyncMark should respect is a good idea here.
    
    
    Some readers are probably wondering why a good dose of atomics isn't obviously the right solution here:  I'm still wondering myself.  I can almost see how to do it, but can't get past the loss of either:
    
      - cheap asyncReady:  as in checking a single word in Interp, with no mutex
      - safety:  Tcl_AsyncMark not causing memory errors if called with a deleted token, a token for a deleted interp, or a token that becomes deleted while AsyncMark is running.
    
  2. login: "aspect"
  3. mimetype: "text/plain"