2.1 Overview 2.3 Simulation Cells
API Reference Manual  /  2 Threading Model  / 

2.2 Basic Module Requirements

To use multi-threading in Simics, all modules used in the simulation must be thread safe. This section describes what it means for a module to be thread safe, and what conditions must be fulfilled.

Note: In this section, thread safe is used in the sense that models instantiated in different cells can be simulated concurrently without issues. This is a weaker definition than normally used.
Simics checks each module it loads to see if it has been marked as safe. A module is thread safe if it fulfills the following conditions:

Below is an example makefile for a module marked as thread safe. It can be found in the [project]/modules/sample-user-decoder directory if the sample-user-decoder has been copied to the project.

MODULE_CLASSES = sample-user-decoder

SRC_FILES = sample-user-decoder.c

SIMICS_API := 6
THREAD_SAFE = yes

include $(MODULE_MAKEFILE)

To make a module thread safe, global state should be avoided, both in the form of global variables and in the form of local static variables in C. Having constant global variables are fine. Modules written in pure DML do not have this problem since the DML compiler does not emit any non-constant global state.

Simics checks for some execution context violations during run-time and emits warnings if they occur. When running with multi-threading disabled, violations result in warnings that can optionally be turned off. With multi-threading enabled, violations cause hard errors.

If a module that is not marked with THREAD_SAFE=yes is loaded, multi-threading will be turned off automatically and a warning will be shown. The list-modules command will show whether a module is marked thread safe or not.

2.1 Overview 2.3 Simulation Cells