{"action":"created","issue":{"url":"https://api.github.com/repos/mquinson/simgrid/issues/19","labels_url":"https://api.github.com/repos/mquinson/simgrid/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/mquinson/simgrid/issues/19/comments","events_url":"https://api.github.com/repos/mquinson/simgrid/issues/19/events","html_url":"https://github.com/mquinson/simgrid/issues/19","id":89243251,"number":19,"title":"Thread safety issue with `SIMIX_process_cleanup()`","user":{"login":"randomstuff","id":946727,"avatar_url":"https://avatars.githubusercontent.com/u/946727?v=3","gravatar_id":"","url":"https://api.github.com/users/randomstuff","html_url":"https://github.com/randomstuff","followers_url":"https://api.github.com/users/randomstuff/followers","following_url":"https://api.github.com/users/randomstuff/following{/other_user}","gists_url":"https://api.github.com/users/randomstuff/gists{/gist_id}","starred_url":"https://api.github.com/users/randomstuff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/randomstuff/subscriptions","organizations_url":"https://api.github.com/users/randomstuff/orgs","repos_url":"https://api.github.com/users/randomstuff/repos","events_url":"https://api.github.com/users/randomstuff/events{/privacy}","received_events_url":"https://api.github.com/users/randomstuff/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mquinson/simgrid/labels/bug","name":"bug","color":"009800"},{"url":"https://api.github.com/repos/mquinson/simgrid/labels/simix","name":"simix","color":"e11d21"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-18T09:23:21Z","updated_at":"2015-06-25T12:40:08Z","closed_at":"2015-06-25T12:40:08Z","body":"While trying to find the root cause of the occasional failure of the kademlia test, I found a thread-safety issue:\r\n\r\n<pre>#7  0x00007ffff79a9b6d in xbt_swag_remove (obj=0x61c2c0, swag=0x60d9b0) at /home/corona/workspace/simgrid/src/xbt/swag.c:141\r\n#8  0x00007ffff78878a9 in SIMIX_process_cleanup (process=0x61c2c0) at /home/corona/workspace/simgrid/src/simix/smx_process.c:96\r\n#9  0x00007ffff78473a5 in MSG_process_cleanup_from_SIMIX (smx_proc=0x61c2c0) at /home/corona/workspace/simgrid/src/msg/msg_process.c:52\r\n#10 0x00007ffff7877ed8 in smx_ctx_base_stop (context=0x61c410) at /home/corona/workspace/simgrid/src/simix/smx_context_base.c:89\r\n#11 0x00007ffff797d31f in smx_ctx_sysv_stop_parallel (context=0x61c410) at /home/corona/workspace/simgrid/src/simix/smx_context_sysv.c:242\r\n#12 0x00007ffff797d0bd in smx_ctx_sysv_wrapper (first=6407184) at /home/corona/workspace/simgrid/src/simix/smx_context_sysv.c:191\r\n#13 0x00007ffff679cf60 in ?? () from /lib/x86_64-linux-gnu/libc.so.6\r\n#14 0x0000000000000000 in ?? ()\r\n</pre>\r\n\r\nWhen running in parallel mode all worker threads can call the `SIMIX_process_cleanup()` concurrently which does things such as:\r\n\r\n~~~c++\r\nXBT_DEBUG(\"%p should not be run anymore\",process);\r\nxbt_swag_remove(process, simix_global->process_list);\r\nxbt_swag_remove(process, SIMIX_host_priv(process->smx_host)->process_list);\r\nxbt_swag_insert(process, simix_global->process_to_destroy);\r\n~~~\r\n\r\nThe SWAG are modified concurrently by the worker threads  without synchronization. In some cases, they go into inconsistent states (for example, `swag->count` is no more consistent with the number of elements really in the swag).\r\n\r\nThe code above those lines might need synchronization as well.\r\n\r\nShall we just add some synchronization here or should this really be done in the maestro (and not in the workers)?\r\n"},"comment":{"url":"https://api.github.com/repos/mquinson/simgrid/issues/comments/115237564","html_url":"https://github.com/mquinson/simgrid/issues/19#issuecomment-115237564","issue_url":"https://api.github.com/repos/mquinson/simgrid/issues/19","id":115237564,"user":{"login":"randomstuff","id":946727,"avatar_url":"https://avatars.githubusercontent.com/u/946727?v=3","gravatar_id":"","url":"https://api.github.com/users/randomstuff","html_url":"https://github.com/randomstuff","followers_url":"https://api.github.com/users/randomstuff/followers","following_url":"https://api.github.com/users/randomstuff/following{/other_user}","gists_url":"https://api.github.com/users/randomstuff/gists{/gist_id}","starred_url":"https://api.github.com/users/randomstuff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/randomstuff/subscriptions","organizations_url":"https://api.github.com/users/randomstuff/orgs","repos_url":"https://api.github.com/users/randomstuff/repos","events_url":"https://api.github.com/users/randomstuff/events{/privacy}","received_events_url":"https://api.github.com/users/randomstuff/received_events","type":"User","site_admin":false},"created_at":"2015-06-25T12:40:08Z","updated_at":"2015-06-25T12:40:08Z","body":"Fixed with a mutex."}}