![]() | ![]() | ![]() | How the system is threaded | ![]() |
The readout software is a highly threaded system. Threading is used to allow the software to cleanly expect and respond to several types of external stimulii.
The threading is done on top of the NSCL DAQ programming framework. The program framework supports separate threads for each stimulus a program may wait for. The threads autonomously wait for a simulus and, when one is recieved, acquire a single global synchronization mutex. This has the effect of simulating an open ended event based programming system within the context of multithreading.
In addition to a standard set of event types, the program framework supports the concept of guest event processing frameworks. Tcl or Tk run as a guest event processing framework. In handling the Tcl interpreter, the assumption is that most Tcl commands (e.g. set) dont' require synchronization. Extensions to the base interpreter are derived from a CDAQTCLProcessor which acquires the syncronization mutex prior to transferring control to the object's operator().
If scripts require synchronization, the Tcl interpreters also support the sync command. The sync command takes a single argument, which is a script that is executed with the global mutex held.
The global mutex is a counting mutex, so there's no penalty to acquire it several times within a single thread, however you must release the mutex the same number of times it has been acquired.
The code example below shows how to use the global syncronization mutex in your code if you work outside the limits of the program framework:
#include <SpectroFramework.h> ... // Unsynchronized. CApplicationSerializer::getInstance()->Lock() // this code is synchronized. CApplicationSerializer::getInstance()->UnLock(); // Unsyncrhonized
The figure below shows the start/stop relationships between the threads of the system:
![]() | ![]() | ![]() | How the system is threaded | ![]() |