C-Sim is a supplement of the C language used to discrete simulation models based on the method of pseudo-parallel processes. Our goal was to make a portable and to a certain degree machine independent tool for computer implementation of discrete systems simulation. The C language was chosen for its portability among different systems (C-Sim is impelmented using the ANSI C specification).
One more argument for choosing C language are the expected nontradicional applications of discrete modeling - verification of properties of parallel programs, communication protocols, fault-tolerant systems and algorithms, real-time programs, etc. Dynamic components (threads, processes) of the modeled program can be mapped to the processes of the simulation program. Other processes (e.g. belonging to a model of program's operational environment) can be added to the model and arbitrary dynamical behavior of the model parts can be prescribed. C language utilization (which is usual in the mentioned application areas) enables simple "rewriting" of verified program parts from the model to the target implementation code.
The idea of C-Sim was taken from the programming language SIMULA and
the library provides SIMULA-like resources from the system classes SIMSET
and SIMULATION. Like SIMULA, the C-Sim uses
the pseudo-parallel processes to describe independent activities of the simulated system.
C-Sim has form of a library of basic object types and operations on them.
The C language (unlike SIMULA) has no tools for object-oriented
programming but some of object-oriented properties were implemented using
predefined macro commands.
Basic supported types, that C-Sim provides, are taken from the original object classes in SIMULA. These are the types:
CSIM_HEAD - two-way circular list,
CSIM_LINK - element of a list,
CSIM_PROCESS - pseudo-parallel process.
Instances of these types in C-Sim based simulation program have to be created exclusively in the dynamically allocated memory (and explicitly discarded, if necessary). Everyone of supported types is provided with a set of functions (i.e. methods of the type). The style of C-Sim utilization can be seen from the joined commented example of a queuing network model.
Context switching of pseudo-parallel processes is implemented by means
of setjmp(), longjmp() functions from the C standard
(stdlib.h) library, so a process needn't to be equiped with its own stack.
Due to this fact, the administration of processes is simple, and it is possible to use
a big number of processes within a simulation program.
A thread is created for each process of the pseudo-parallel processes method. In this implementation it is however necessary to assure that only one thread is being executed at a time.
The file csim_kr.h that implements the mechanism of pseudo-parallel processes is provided in two versions. The directory kr_jmp contains the version based on long jumps, the directory kr_thr contains version based on POSIX threads. Library user may choose desired implementation at compile time by defining the macro KR_PATH on the compiler command line.
The lowest layer contains the definitions of data types and implements pseudo-parallel processes. The second layer contains definitions of data types, macros and functions for creating a simulation model and for controlling the simulation flow. Functions for dynamic memory control and for object checking are also defined in this layer. The third layer contains optional modules: