6 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example,
7 "Messages specific for this msg example");
11 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);
32 int main(int argc, char* argv[]) {
34 MSG_init(&argc, argv);
35 MSG_create_environment(argv[1]);
37 xbt_dynar_t hosts = MSG_hosts_as_dynar();
38 msg_host_t h = xbt_dynar_get_as(hosts,0,msg_host_t);
40 sem = MSG_sem_init(1);
41 char** aliceTimes = xbt_new(char*, 9);
43 aliceTimes[nbAlice++] = xbt_strdup("0");
44 aliceTimes[nbAlice++] = xbt_strdup("1");
45 aliceTimes[nbAlice++] = xbt_strdup("3");
46 aliceTimes[nbAlice++] = xbt_strdup("5");
47 aliceTimes[nbAlice++] = xbt_strdup("1");
48 aliceTimes[nbAlice++] = xbt_strdup("2");
49 aliceTimes[nbAlice++] = xbt_strdup("5");
50 aliceTimes[nbAlice++] = xbt_strdup("0");
51 aliceTimes[nbAlice++] = NULL;
53 char** bobTimes = xbt_new(char*, 9);
55 bobTimes[nbBob++] = xbt_strdup("0.9");
56 bobTimes[nbBob++] = xbt_strdup("1");
57 bobTimes[nbBob++] = xbt_strdup("1");
58 bobTimes[nbBob++] = xbt_strdup("2");
59 bobTimes[nbBob++] = xbt_strdup("2");
60 bobTimes[nbBob++] = xbt_strdup("0");
61 bobTimes[nbBob++] = xbt_strdup("0");
62 bobTimes[nbBob++] = xbt_strdup("5");
63 bobTimes[nbBob++] = NULL;
66 MSG_process_create_with_arguments(xbt_strdup("Alice"), peer, NULL,
68 MSG_process_create_with_arguments(xbt_strdup("Bob"), peer, NULL,
71 msg_error_t res = MSG_main();