X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c53d0aac5a5ab41701f3320d95f1cd2b0f3fd005..478eeb617b0ea4414850b4d2dd3e5305b19e3404:/doc/gtut-tour-05-globals.doc diff --git a/doc/gtut-tour-05-globals.doc b/doc/gtut-tour-05-globals.doc index 32450ce17f..da702fdba4 100644 --- a/doc/gtut-tour-05-globals.doc +++ b/doc/gtut-tour-05-globals.doc @@ -6,7 +6,7 @@ - \ref GRAS_tut_tour_globals_use - \ref GRAS_tut_tour_callback_pitfall - \ref GRAS_tut_tour_callback_recap - +
\section GRAS_tut_tour_globals_intro Introduction @@ -21,24 +21,24 @@ within the same naming space in SG so your globals will be shared between the several instances of your process, leading to bad problems. Instead, you you have to put all globals in a structure, and let GRAS handle -it with the gras_userdata_* functions (there is only 3 of them ;). +it with the gras_userdata_* functions (there is only 3 of them ;). \section GRAS_tut_tour_globals_use Putting globals into action We will now modify the example to add a "kill" message, and let the server loop on incoming messages until it gets such a message. We only need a -boolean, so the structure is quite simple: -\don'tinclude 05-globals.c +boolean, so the structure is quite simple: +\dontinclude 05-globals.c \skip struct \until server_data - + Then, we need to create this structure in the process main function. We could use either gras_userdata_new() or gras_userdata_set(). The former is an helper macro mallocing the space needed by the structure and passing it to gras using the latter function. If you go for gras_userdata_set(), you should pass it a pointer to your data you want to retrieve afterward. -\don'tinclude 05-globals.c +\dontinclude 05-globals.c \skip userdata_new \until userdata_new @@ -49,13 +49,13 @@ defined as being of type server_data_t*. Once you declared a global that way, retriving this (for example in a callback) is really easy: -\don'tinclude 05-globals.c +\dontinclude 05-globals.c \skip userdata_get \until userdata_get We can now write the callback, which simply retrive the globals and change the value of the kileld field. -\don'tinclude 05-globals.c +\dontinclude 05-globals.c \skip kill_cb \until end_of_kill_callback @@ -78,9 +78,9 @@ This is to write something like: \verbatim int server(int argc, char *argv[]) { server_data_t globals=gras_user_new(server_data_t); /* other variable definition */ - + gras_init(&argc, argv); - + /* rest of the code */ }\endverbatim