AST Objects within Multi-threaded Applications

When the AST library is built from source, the build process checks to see if the POSIX threads library (“pthreads”) is available. If so, appropriate pthreads calls are inserted into the AST source code to ensure that AST is thread-safe, and the AST__THREADSAFE macro (defined in the “ast.h” header file) is set to “1”. If the pthreads library cannot be found when AST is built, a working version of the AST library will still be created, but it will not be thread-safe. In this case the AST__THREADSAFE macro will be set to “0” in ast.h. The rest of this section assumes that the thread-safe version of AST is being used.

Note, some AST functions call externally specified functions (e.g. the source and sink functions used by the ChannelChannel class or the graphics primitives functions used by the PlotPlot class). AST does not know whether such functions are thread-safe or not. For this reason, invocations of these functions within a multi-threaded environment are serialised using a mutex in order to avoid two or more threads executing an external function simultaneously.

If an application uses more than one thread, the possibility arises that an ObjectObject created by one thread may be accessed by another thread, potentially simultaneously. If any of the threads modifies any aspect of the Object, this could lead to serious problems within the other threads. For this reason, some restrictions are placed on how Objects can be used in a multi-threaded application.



Subsections