There is no automatic refcounting in C so when a process is killed, we
must free it immediately. We could maybe propose a workaround to allow
the users to increase the refcount themself (as needed for #248), but
it's much easier to convert your code to C++ than getting the manual
refcounting right, I'd say. Sorry...
The fix to #248 leads to invalid accesses detected by valgrind when
applied to C/MSG.
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_kill, "Messages specific for this msg example");
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_kill, "Messages specific for this msg example");
-static int victimA_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+static int victim_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
{
XBT_INFO("Hello!");
XBT_INFO("Suspending myself");
{
XBT_INFO("Hello!");
XBT_INFO("Suspending myself");
-static int victimB_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
-{
- XBT_INFO("Terminates before being killed");
- return 0;
-}
-
static int killer(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
{
XBT_INFO("Hello!"); /* - First start a victim process */
static int killer(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
{
XBT_INFO("Hello!"); /* - First start a victim process */
- msg_process_t victimA = MSG_process_create("victim A", victimA_fun, NULL, MSG_host_by_name("Fafard"));
- msg_process_t victimB = MSG_process_create("victim B", victimB_fun, NULL, MSG_host_by_name("Bourassa"));
+ msg_process_t victim = MSG_process_create("victim", victim_fun, NULL, MSG_host_by_name("Fafard"));
- XBT_INFO("Resume victimA"); /* - Resume it from its suspended state */
- MSG_process_resume(victimA);
-
- XBT_INFO("Kill victimA"); /* - and then kill it */
- MSG_process_kill(victimA);
+ XBT_INFO("Resume victim"); /* - Resume it from its suspended state */
+ MSG_process_resume(victim);
- XBT_INFO("Kill victimB, even if it's already dead"); /* that's a no-op, there is no zombies in SimGrid */
- MSG_process_kill(victimB);
+ XBT_INFO("Kill victim"); /* - and then kill it */
+ MSG_process_kill(victim);
XBT_INFO("OK, goodbye now. I commit a suicide.");
MSG_process_kill(MSG_process_self());
XBT_INFO("OK, goodbye now. I commit a suicide.");
MSG_process_kill(MSG_process_self());
$ $SG_TEST_EXENV ${bindir:=.}/process-kill ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (1:killer@Tremblay) Hello!
$ $SG_TEST_EXENV ${bindir:=.}/process-kill ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (1:killer@Tremblay) Hello!
-> [ 0.000000] (2:victim A@Fafard) Hello!
-> [ 0.000000] (2:victim A@Fafard) Suspending myself
-> [ 0.000000] (3:victim B@Bourassa) Terminates before being killed
-> [ 10.000000] (1:killer@Tremblay) Resume victimA
-> [ 10.000000] (1:killer@Tremblay) Kill victimA
-> [ 10.000000] (1:killer@Tremblay) Kill victimB, even if it's already dead
+> [ 0.000000] (2:victim@Fafard) Hello!
+> [ 0.000000] (2:victim@Fafard) Suspending myself
+> [ 10.000000] (1:killer@Tremblay) Resume victim
+> [ 10.000000] (1:killer@Tremblay) Kill victim
> [ 10.000000] (1:killer@Tremblay) OK, goodbye now. I commit a suicide.
> [ 10.000000] (0:maestro@) Simulation time 10
> [ 10.000000] (1:killer@Tremblay) OK, goodbye now. I commit a suicide.
> [ 10.000000] (0:maestro@) Simulation time 10