X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/830b5c4bc694ade087c43f39015faa9065795630..8be7ea3f9e71cd563e91b6aba63f5c70f043fbd5:/examples/msg/cloud/masterslave_virtual_machines.c diff --git a/examples/msg/cloud/masterslave_virtual_machines.c b/examples/msg/cloud/masterslave_virtual_machines.c index b0a073a2fb..33513a0bf3 100644 --- a/examples/msg/cloud/masterslave_virtual_machines.c +++ b/examples/msg/cloud/masterslave_virtual_machines.c @@ -1,4 +1,5 @@ -/* Copyright (c) 2007-2012. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2013. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -63,7 +64,11 @@ int master(int argc, char *argv[]) { argv[0] = xbt_strdup(slavename); argv[1] = bprintf("%d",i); argv[2] = NULL; - msg_vm_t vm = MSG_vm_start(slaves[i],2); + + char vmName[64]; + snprintf(vmName, 64, "vm_%d", i); + + msg_vm_t vm = MSG_vm_start(slaves[i],vmName,2); MSG_vm_bind(vm, MSG_process_create_with_arguments(slavename,slave_fun,NULL,slaves[i],2,argv)); } @@ -130,6 +135,9 @@ int master(int argc, char *argv[]) { MSG_task_send(finalize, mailbox_buffer); } + XBT_INFO("Wait a while before effective shutdown."); + MSG_process_sleep(2); + xbt_dynar_foreach(vms,i,vm) { MSG_vm_shutdown(vm); MSG_vm_destroy(vm); @@ -144,12 +152,12 @@ int master(int argc, char *argv[]) { /** Receiver function */ int slave_fun(int argc, char *argv[]) { - char *mailbox_name; + char mailbox_name[128]; msg_task_t task = NULL; _XBT_GNUC_UNUSED int res; /* since the slaves will move around, use slave_%d as mailbox names instead of hostnames */ xbt_assert(argc>=2, "slave processes need to be given their rank as parameter"); - mailbox_name=bprintf("Slave_%s",argv[1]); + sprintf(mailbox_name,"Slave_%s",argv[1]); XBT_INFO("Slave listenning on %s",argv[1]); while (1) { res = MSG_task_receive(&(task),mailbox_name); @@ -167,7 +175,6 @@ int slave_fun(int argc, char *argv[]) task = NULL; } - free(mailbox_name); return 0; } /* end_of_slave */ @@ -213,6 +220,8 @@ int main(int argc, char *argv[]) XBT_INFO("Simulation time %g", MSG_get_clock()); free(hosts); + for (i=0;i<10;i++) + free(hostnames[i]); free(hostnames); xbt_dynar_free(&hosts_dynar);