X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f122b5ee75cf18cd4ba58d081677e44763716203..ed9b07e5c0c7eb6d4d38b0fe5aaea80d6996a8a7:/examples/msg/semaphores/synchro.c?ds=sidebyside diff --git a/examples/msg/semaphores/synchro.c b/examples/msg/semaphores/synchro.c index fef6142aef..01dcd02834 100644 --- a/examples/msg/semaphores/synchro.c +++ b/examples/msg/semaphores/synchro.c @@ -1,6 +1,12 @@ +/* Copyright (c) 2013-2014. 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. */ + #include #include -#include "msg/msg.h" +#include "simgrid/msg.h" #include "xbt/log.h" XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example, @@ -8,24 +14,27 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example, msg_sem_t sem; -int peer(int argc, char* argv[]){ +static int peer(int argc, char* argv[]){ int i = 0; while(i < argc) { double wait_time = atof(argv[i++]); MSG_process_sleep(wait_time); - XBT_INFO("Trying to acquire"); + XBT_INFO("Trying to acquire %d", i); MSG_sem_acquire(sem); - XBT_INFO("Acquired"); + XBT_INFO("Acquired %d", i); wait_time = atof(argv[i++]); MSG_process_sleep(wait_time); - XBT_INFO("Releasing"); + XBT_INFO("Releasing %d", i); MSG_sem_release(sem); - XBT_INFO("Released"); + XBT_INFO("Released %d", i); } + MSG_process_sleep(50); + XBT_INFO("Done"); + return 0; } int main(int argc, char* argv[]) { @@ -36,16 +45,38 @@ int main(int argc, char* argv[]) { xbt_dynar_t hosts = MSG_hosts_as_dynar(); msg_host_t h = xbt_dynar_get_as(hosts,0,msg_host_t); + sem = MSG_sem_init(1); + char** aliceTimes = xbt_new(char*, 9); + int nbAlice = 0; + aliceTimes[nbAlice++] = xbt_strdup("0"); + aliceTimes[nbAlice++] = xbt_strdup("1"); + aliceTimes[nbAlice++] = xbt_strdup("3"); + aliceTimes[nbAlice++] = xbt_strdup("5"); + aliceTimes[nbAlice++] = xbt_strdup("1"); + aliceTimes[nbAlice++] = xbt_strdup("2"); + aliceTimes[nbAlice++] = xbt_strdup("5"); + aliceTimes[nbAlice++] = xbt_strdup("0"); + aliceTimes[nbAlice++] = NULL; - char* aliceTimes[] = {"0", "1", "3", "5", "1", "2", "5", "0"}; - char* bobTimes[] = {"1", "1", "1", "2", "2", "0", "0", "5"}; + char** bobTimes = xbt_new(char*, 9); + int nbBob = 0; + bobTimes[nbBob++] = xbt_strdup("0.9"); + bobTimes[nbBob++] = xbt_strdup("1"); + bobTimes[nbBob++] = xbt_strdup("1"); + bobTimes[nbBob++] = xbt_strdup("2"); + bobTimes[nbBob++] = xbt_strdup("2"); + bobTimes[nbBob++] = xbt_strdup("0"); + bobTimes[nbBob++] = xbt_strdup("0"); + bobTimes[nbBob++] = xbt_strdup("5"); + bobTimes[nbBob++] = NULL; + - - MSG_process_create_with_arguments("Alice", peer, NULL, + MSG_process_create_with_arguments(xbt_strdup("Alice"), peer, NULL, h, 8, aliceTimes); - MSG_process_create_with_arguments("Bob", peer, NULL, + MSG_process_create_with_arguments(xbt_strdup("Bob"), peer, NULL, h, 8, bobTimes); - MSG_main(); - + msg_error_t res = MSG_main(); + printf("Finished\n"); + return (res != MSG_OK); }