The GitHub demo project https://github.com/mrabchevskiy/coherent contains components that implement the approach described in the previous chapter MULTICORE AND MULTITHREADING III. SOLUTION: PRINCIPLES.
Recall that we are talking about an alternative variant of organizing a parallel work of a set of logical processes using shared data; the development of this version pursued the following goals:
elimination of overhead costs of computing resources when synchronizing data access using standard mutex and its derivatives, leading to thread interruption (context switch) or idle work in case of spinlock;
simplification of code writing, debugging, and elimination of conditions leading to deadlock;
the ability to embed a system for monitoring and collecting statistics on the execution of many parallel logical processes.
These goals are achievable because standard data protection tools (std::mutex and its derivatives) were developed in a different, much narrower context: "There is a data set, a means of organizing correct access from more than one thread is required." In the present case, it is assumed that there are many data objects and many simultaneously performed logical processes, which is illustrated by the previously mentioned scheme:
Source code is written in a "self-documenting" style; that is, it assumes that the user is reading the code, and comments combined with meaningful naming and code formatting make separate documentation (which tends not to keep up with code modification) redundant.
Main demo application components:
coherent.cpp - main file of the demo application; includes the data class definition available to a series of logical processes.
fluid.h - a templated wrapper that turns an arbitrary data class into a protected/synchronized object, providing simultaneous read access to data and exclusive write access. The data access algorithm is implemented as a state machine with an explicitly defined graph of transitions between valid states.
logical.process.h - a wrapper that turns an ordinary function into an instance of a parallel logical process served by a pool of non-stop threads.
staff.h - non-stop thread pull that performs calculations in all logical processes
brief.log, wordy.log - example of demo application log files
An auxiliary application that generates pdf files with state transition graph image state machine fluid.h (a helpful tool for analysis, debugging, and modification):
info.cpp - main file
fluid.auxiliary.h - functions that generate .dot files (see details below) using state transitions defined in the fluid.h
Fluid-transition.R.dot, Fluid-transition.W.dot - description files of the state machine transition graph (defined in fluid.h) in the format accepted for the `dot` graph manipulation utility (details in https://graphviz.org/ ).
dot.sh - shell script to convert *.dot files to *.pdf document
Fluid-transition.R.pdf, Fluid-transition.W.pdf - generated images of transition graphs.
Utility classes used by the components listed above:
logger.h
logger.global.h
chronos.h
color.h
config.h
def.h
queue.h
range.h
semantic.type.h
timer.h
More details are available upon request ( ai@ockhamstyle.com ).