Typedef cimba_trial_func
Defined in File cimba.h
Typedef Documentation
- void() cimba_trial_func (void *trial_struct)
Defines a prototype for the user-implemented function to execute a single trial of the experiment.
Your simulated universe lives inside this function, using the tools provided by Cimba. The argument points to a user-defined trial struct containing the parameters to and the results from the trial. It is defined as a
void*here since we do not know what your struct will contain. The trial function does not return a value but stores the results in the same struct as the parameters.This function will be executed in parallel with other instances of itself in a shared memory space. Do not use writeable global variables to share data between functions inside your simulated world. Do not use static local variables to remember values between calls to some function. If you do, it will easily lead to undefined behavior when different threads execute in parallel in the same memory space, reading and writing the variable values in unpredictable sequences. Using normal (auto) local variables and function arguments is safe.
If you absolutely must have a global or static variable to be shared between function calls, declare it
CMB_THREAD_LOCALto keep it local to that simulation thread (but it may still be shared across successive trials that happen to share the same worker thread, with possibly unexpected results unless you are careful in initializing and clearing the variable in each trial). Alternatively, put amutexon it, or other methods to make it thread safe.