Documentation for the problem of non-reentrant function
Inria Forge bug #14698: https://gforge.inria.fr/tracker/index.php?func=detail&aid=14698&group_id=12&atid=165
From: Jean-Noel Quintin
Date: 07/08/2012 11:15
when we start to use simgrid this not obvious that simgrid uses some user threads to simulate the processes. we can provide at least some warning inside the examples like for getopt.
I copy here the last part of the discussion:
When we parse the parameter inside the simulated process, we could add:
//Take care to reinitialize getopt environment for the next process which shared the global variable
//All the global variable are shared between the processes (see documentation...).
optind=1;
while ((opt = getopt(argc, argv, "h")) != -1) {
//don't call any functions of simgrid between the call to getopt
//this could reinitialize the parsing of some process and lead to a strange behavior.
switch(opt) {
.....
}
}
And if you have a pointer on a part of the documentation (which describe how are organize the process context), we could add it. Moreover, I would put something inside the FAQ (with the word reentrant, thread-safe, global-variable). If this is in most of the examples, I think that the people would think about it.
Best regards,
Jean-Noël