1 /* Copyright (c) 2013-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/msg.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example, "Messages specific for this msg example");
13 static int peer(int argc, char* argv[]){
16 double wait_time = xbt_str_parse_double(argv[i++],"Invalid wait time: %s");
17 MSG_process_sleep(wait_time);
18 XBT_INFO("Trying to acquire %d", i);
20 XBT_INFO("Acquired %d", i);
22 wait_time = xbt_str_parse_double(argv[i++], "Invalid wait time: %s");
23 MSG_process_sleep(wait_time);
24 XBT_INFO("Releasing %d", i);
26 XBT_INFO("Released %d", i);
28 MSG_process_sleep(50);
34 int main(int argc, char* argv[])
36 MSG_init(&argc, argv);
37 MSG_create_environment(argv[1]);
39 xbt_dynar_t hosts = MSG_hosts_as_dynar();
40 msg_host_t h = xbt_dynar_get_as(hosts,0,msg_host_t);
41 xbt_dynar_free(&hosts);
43 sem = MSG_sem_init(1);
44 char** aliceTimes = xbt_new(char*, 9);
46 aliceTimes[nbAlice++] = xbt_strdup("0");
47 aliceTimes[nbAlice++] = xbt_strdup("1");
48 aliceTimes[nbAlice++] = xbt_strdup("3");
49 aliceTimes[nbAlice++] = xbt_strdup("5");
50 aliceTimes[nbAlice++] = xbt_strdup("1");
51 aliceTimes[nbAlice++] = xbt_strdup("2");
52 aliceTimes[nbAlice++] = xbt_strdup("5");
53 aliceTimes[nbAlice++] = xbt_strdup("0");
54 aliceTimes[nbAlice++] = NULL;
56 char** bobTimes = xbt_new(char*, 9);
58 bobTimes[nbBob++] = xbt_strdup("0.9");
59 bobTimes[nbBob++] = xbt_strdup("1");
60 bobTimes[nbBob++] = xbt_strdup("1");
61 bobTimes[nbBob++] = xbt_strdup("2");
62 bobTimes[nbBob++] = xbt_strdup("2");
63 bobTimes[nbBob++] = xbt_strdup("0");
64 bobTimes[nbBob++] = xbt_strdup("0");
65 bobTimes[nbBob++] = xbt_strdup("5");
66 bobTimes[nbBob++] = NULL;
68 MSG_process_create_with_arguments(xbt_strdup("Alice"), peer, NULL, h, 8, aliceTimes);
69 MSG_process_create_with_arguments(xbt_strdup("Bob"), peer, NULL, h, 8, bobTimes);
71 msg_error_t res = MSG_main();
72 XBT_INFO("Finished\n");
73 return (res != MSG_OK);