SimGrid  3.7
Scalable simulation of distributed systems
Defines | Functions
Globals
Virtualization

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

Defines

#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: Lesson 5: Using globals in processes


Define 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: Lesson 5: Using globals in processes


Back to the main Simgrid Documentation page The version of SimGrid documented here is v3.7.
Documentation of other versions can be found in their respective archive files (directory doc/html).
Generated by doxygen