SimGrid  3.8.1
Scalable Simulation of Distributed Systems - Reference Manual
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Globals

Handling global variables so that it works on simulator. More...

Macros

#define gras_userdata_new(type)   ((type*)gras_userdata_set(xbt_new0(type,1)))
 Malloc and set the data associated with the current process.

Functions

void gras_agent_spawn (const char *name, xbt_main_func_t code, int argc, char *argv[], xbt_dict_t properties)
 Create a new thread.
void * gras_userdata_get (void)
 Get the data associated with the current process.
void * gras_userdata_set (void *ud)
 Set the data associated with the current process.

Detailed Description

Handling global variables so that it works on simulator.

In GRAS, using globals is forbidden since the "processes" will sometimes run as a thread inside the same process (namely, in simulation mode). So, you have to put all globals in a structure, and let GRAS handle it.

Use the gras_userdata_new macro to create a new user data (or malloc it and use gras_userdata_set yourself), and gras_userdata_get to retrieve a reference to it.

For more info on this, you may want to check the relevant lesson of the GRAS tutorial online

Macro Definition Documentation

#define gras_userdata_new (   type)    ((type*)gras_userdata_set(xbt_new0(type,1)))

Malloc and set the data associated with the current process.

Warning
gras_userdata_new() expects the pointed type, not the pointer type. We know it'a a bit troublesome, but it seems like the only solution since this macro has to compute the size to malloc and should thus know the pointed type.

You'll find an example in the tutorial