6 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example,
7 "Messages specific for this msg example");
11 static int peer(int argc, char* argv[]){
16 double wait_time = atof(argv[i++]);
17 MSG_process_sleep(wait_time);
18 XBT_INFO("Trying to acquire %d", i);
20 XBT_INFO("Acquired %d", i);
22 wait_time = atof(argv[i++]);
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);
42 sem = MSG_sem_init(1);
43 char** aliceTimes = xbt_new(char*, 9);
45 aliceTimes[nbAlice++] = xbt_strdup("0");
46 aliceTimes[nbAlice++] = xbt_strdup("1");
47 aliceTimes[nbAlice++] = xbt_strdup("3");
48 aliceTimes[nbAlice++] = xbt_strdup("5");
49 aliceTimes[nbAlice++] = xbt_strdup("1");
50 aliceTimes[nbAlice++] = xbt_strdup("2");
51 aliceTimes[nbAlice++] = xbt_strdup("5");
52 aliceTimes[nbAlice++] = xbt_strdup("0");
53 aliceTimes[nbAlice++] = NULL;
55 char** bobTimes = xbt_new(char*, 9);
57 bobTimes[nbBob++] = xbt_strdup("0.9");
58 bobTimes[nbBob++] = xbt_strdup("1");
59 bobTimes[nbBob++] = xbt_strdup("1");
60 bobTimes[nbBob++] = xbt_strdup("2");
61 bobTimes[nbBob++] = xbt_strdup("2");
62 bobTimes[nbBob++] = xbt_strdup("0");
63 bobTimes[nbBob++] = xbt_strdup("0");
64 bobTimes[nbBob++] = xbt_strdup("5");
65 bobTimes[nbBob++] = NULL;
68 MSG_process_create_with_arguments(xbt_strdup("Alice"), peer, NULL,
70 MSG_process_create_with_arguments(xbt_strdup("Bob"), peer, NULL,
73 msg_error_t res = MSG_main();
75 return (res != MSG_OK);