To call reentrant code, create a main
function
that:
Includes the header file primary_function_name
.h.
For each thread, allocates memory for the global memory
allocation structure primary_function_name
StackData
.
If the algorithm uses persistent or global data, allocates memory for the global structure
primary_function_name
PersistentData
.
If the threads communicate, allocate this memory once for the root process.
Otherwise, you can allocate memory per thread.
Contains a thread function that calls these functions:
primary_function_name
_initialize
.
primary_function_name
.
primary_function_name
_terminate
.
When you convert a MATLAB® function to a C/C++ library function or a C/C++ executable, MATLAB Coder™ generates two housekeeping functions. Call these functions in the code that calls the generated C/C++ function. For more information, see Deploy Generated Code.
Initializes each thread and passes in a pointer to the memory allocation structure as the first parameter to the thread function.
Frees up the memory used for global structures.
Type of Reentrant Code | Platform | Reference |
---|---|---|
Multithreaded without persistent or global data | Windows® | Generate Reentrant C Code from MATLAB Code |
UNIX® | Call Reentrant Code with No Persistent or Global Data (UNIX Only) | |
Multithreaded with persistent or global data | Windows | Call Reentrant Code — Multithreaded with Persistent Data (Windows Only) |
UNIX | Call Reentrant Code — Multithreaded with Persistent Data (UNIX Only) |