Skip to content
  • Jameson Rollins's avatar
    single thread: move CAS processing out of separate thread into main daemon thread thread · 4c853b8b
    Jameson Rollins authored
    This is a fairly large overhaul of the original threading model that had
    the pcaspy portable channel access server in a separate thread.  We here
    bring the cas back in to the main thread, and process it's select loop at
    the top of the daemon main loop.
    
    Digging into the seg faults [0] with an instrumented address sanitizer
    versions of python and pcaspy we discovered that pcaspy is not thread safe.
    When run in a separate thread pcaspy was producing a strncpy
    heap-use-after-free when pushing the unit CTRL sub-record (gdb showed that
    it was in strncpy of the string "seconds", where the only use of "seconds"
    in guardian is in unit sub-record for EXECTIME).  Attempts to wrap guardian's
    reading and writing to cas driver records was not sufficient, and cas does
    not provide any hooks to locks for it's access either.  So why not try to
    get rid of the separate cas thread altogether...
    
    The cas.process() is moved in to the dead time at the top of the main daemon
    loop, where it was waiting for the clock tick. This has the side affect of actually
    synchonizing to the wall clock microsecond step (good?).
    
    The rest of the patch is just cleanup to remove all the old thread/lock
    stuff that is no longer needed, and to simplify the relevant interfaces.
    
    [0] https://alog.ligo-wa.caltech.edu/aLOG/index.php?callRep=40765
    4c853b8b