Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix thread safety issue in process cleanup
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 19 Jun 2015 09:34:54 +0000 (11:34 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Thu, 25 Jun 2015 12:36:57 +0000 (14:36 +0200)
commitbe00fecb16c89d44253052889f4815b35ab9abbe
treebaa930ca79abc62d915674a350038dba260541f7
parentfe6302bb22ba202d3e193ee8ec436c14adb7ecd6
Fix thread safety issue in process cleanup

While trying to find the root cause of the occasional failure of the
kademlia test, I found a thread-safety issue here:

When running in parallel mode all worker threads can call the
`SIMIX_process_cleanup()` concurrently which does things such as:

~~~c++
XBT_DEBUG("%p should not be run anymore",process);
xbt_swag_remove(process, simix_global->process_list);
xbt_swag_remove(process, SIMIX_host_priv(process->smx_host)->process_list);
xbt_swag_insert(process, simix_global->process_to_destroy);
~~~

The SWAG are modified concurrently by the worker threads without
synchronization. Sometimes, they go into inconsistent states (for
example, `swag->count` is no more consistent with the number of
elements really in the swag).

This fix might not be the best way to do it.
src/simix/smx_global.c
src/simix/smx_private.h
src/simix/smx_process.c