Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert sychro-semaphore
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 21 Mar 2020 10:05:43 +0000 (11:05 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 21 Mar 2020 10:05:43 +0000 (11:05 +0100)
MANIFEST.in
examples/c/CMakeLists.txt
examples/c/synchro-semaphore/synchro-semaphore.c [new file with mode: 0644]
examples/c/synchro-semaphore/synchro-semaphore.tesh [moved from examples/deprecated/msg/synchro-semaphore/synchro-semaphore.tesh with 93% similarity]
examples/deprecated/msg/CMakeLists.txt
examples/deprecated/msg/synchro-semaphore/synchro-semaphore.c [deleted file]

index b9ba73a..f5de1fa 100644 (file)
@@ -127,6 +127,8 @@ include examples/c/platform-properties/platform-properties.tesh
 include examples/c/platform-properties/platform-properties_d.xml
 include examples/c/plugin-hostload/plugin-hostload.c
 include examples/c/plugin-hostload/plugin-hostload.tesh
+include examples/c/synchro-semaphore/synchro-semaphore.c
+include examples/c/synchro-semaphore/synchro-semaphore.tesh
 include examples/deprecated/java/app/bittorrent/Common.java
 include examples/deprecated/java/app/bittorrent/Connection.java
 include examples/deprecated/java/app/bittorrent/Main.java
@@ -273,8 +275,6 @@ include examples/deprecated/msg/mc/deploy_centralized_mutex.xml
 include examples/deprecated/msg/mc/platform.xml
 include examples/deprecated/msg/mc/promela_bugged1_liveness
 include examples/deprecated/msg/mc/promela_bugged2_liveness
-include examples/deprecated/msg/synchro-semaphore/synchro-semaphore.c
-include examples/deprecated/msg/synchro-semaphore/synchro-semaphore.tesh
 include examples/deprecated/msg/trace-categories/trace-categories.c
 include examples/deprecated/msg/trace-categories/trace-categories.tesh
 include examples/deprecated/msg/trace-host-user-variables/trace-host-user-variables.c
index e74de6e..730e6b7 100644 (file)
@@ -11,7 +11,8 @@ foreach(x
         energy-exec energy-exec-ptask energy-vm
         io-disk-raw io-file-remote
         platform-failures platform-properties
-        plugin-hostload)
+        plugin-hostload
+        synchro-semaphore)
   add_executable       (${x}-c EXCLUDE_FROM_ALL ${x}/${x}.c)
   target_link_libraries(${x}-c simgrid)
   set_target_properties(${x}-c PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
@@ -65,7 +66,7 @@ set(tesh_files    ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/app-b
                                 ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-vivaldi.tesh
                                 ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/dht-kademlia.tesh
                                 PARENT_SCOPE)
-set(bin_files     ${bin_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/generate.py                  
+set(bin_files     ${bin_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/generate.py
                                ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/generate.py                        PARENT_SCOPE)
 set(examples_src  ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/common.h
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/dht-kademlia.c                  PARENT_SCOPE)
@@ -99,7 +100,8 @@ foreach(x
         energy-exec energy-exec-ptask energy-vm
         io-disk-raw io-file-remote
         platform-failures platform-properties
-        plugin-hostload)
+        plugin-hostload
+        synchro-semaphore)
   ADD_TESH(c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
                   --setenv bindir=${CMAKE_BINARY_DIR}/examples/c/${x}
                   --cd ${CMAKE_HOME_DIRECTORY}/examples/c/${x}
@@ -107,19 +109,19 @@ foreach(x
 endforeach()
 
 ADD_TESH_FACTORIES(app-masterworker-multicore   "thread;ucontext;raw;boost" 
-                                                --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/c/app-masterworker 
+                                                --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/c/app-masterworker
                                                 --setenv bindir=${CMAKE_BINARY_DIR}/examples/c/app-masterworker
                                                 --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
                                                ${CMAKE_HOME_DIRECTORY}/examples/c/app-masterworker/app-masterworker-multicore.tesh)
 ADD_TESH_FACTORIES(app-masterworker-vivaldi     "thread;ucontext;raw;boost" 
-                                                --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/c/app-masterworker 
+                                                --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/c/app-masterworker
                                                 --setenv bindir=${CMAKE_BINARY_DIR}/examples/c/app-masterworker
                                                 --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
                                                 ${CMAKE_HOME_DIRECTORY}/examples/c/app-masterworker/app-masterworker-vivaldi.tesh)
 ADD_TESH_FACTORIES(c-dht-kademlia "thread;ucontext;raw;boost" 
                                   --setenv bindir=${CMAKE_BINARY_DIR}/examples/c/dht-kademlia
-                                  --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/c/dht-kademlia 
-                                  --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms 
+                                  --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/c/dht-kademlia
+                                  --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
                                   ${CMAKE_HOME_DIRECTORY}/examples/c/dht-kademlia/dht-kademlia.tesh)
 
 if(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
diff --git a/examples/c/synchro-semaphore/synchro-semaphore.c b/examples/c/synchro-semaphore/synchro-semaphore.c
new file mode 100644 (file)
index 0000000..6ae0201
--- /dev/null
@@ -0,0 +1,59 @@
+/* Copyright (c) 2013-2020. 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 "simgrid/actor.h"
+#include "simgrid/engine.h"
+#include "simgrid/host.h"
+#include "simgrid/semaphore.h"
+
+#include "xbt/log.h"
+#include "xbt/str.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(semaphores, "Messages specific for this example");
+
+sg_sem_t sem;
+
+static void peer(int argc, char* argv[])
+{
+  int i = 0;
+  while (i < argc) {
+    double wait_time = xbt_str_parse_double(argv[i], "Invalid wait time: %s");
+    i++;
+    sg_actor_sleep_for(wait_time);
+    XBT_INFO("Trying to acquire %d", i);
+    sg_sem_acquire(sem);
+    XBT_INFO("Acquired %d", i);
+
+    wait_time = xbt_str_parse_double(argv[i], "Invalid wait time: %s");
+    i++;
+    sg_actor_sleep_for(wait_time);
+    XBT_INFO("Releasing %d", i);
+    sg_sem_release(sem);
+    XBT_INFO("Released %d", i);
+  }
+  sg_actor_sleep_for(50);
+  XBT_INFO("Done");
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid_init(&argc, argv);
+  simgrid_load_platform(argv[1]);
+
+  sg_host_t h = sg_host_by_name("Fafard");
+
+  sem                      = sg_sem_init(1);
+  const char* aliceTimes[] = {"0", "1", "3", "5", "1", "2", "5", "0"};
+  const char* bobTimes[]   = {"0.9", "1", "1", "2", "2", "0", "0", "5"};
+
+  sg_actor_create("Alice", h, peer, 8, aliceTimes);
+  sg_actor_create("Bob", h, peer, 8, bobTimes);
+
+  simgrid_run();
+  sg_sem_destroy(sem);
+  XBT_INFO("Finished\n");
+  return 0;
+}
@@ -3,7 +3,7 @@
 p Testing synchronization with semaphores
 
 ! output sort 19
-$ ${bindir:=.}/synchro-semaphore ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+$ ${bindir:=.}/synchro-semaphore-c ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
 > [  0.000000] (1:Alice@Fafard) Trying to acquire 1
 > [  0.000000] (1:Alice@Fafard) Acquired 1
 > [  0.900000] (2:Bob@Fafard) Trying to acquire 1
index 6d634a5..b427502 100644 (file)
@@ -1,4 +1,4 @@
-foreach(x dht-pastry synchro-semaphore trace-categories trace-route-user-variables trace-link-user-variables 
+foreach(x dht-pastry trace-categories trace-route-user-variables trace-link-user-variables 
         trace-masterworker trace-process-migration trace-host-user-variables)
   if(enable_msg)
     add_executable       (${x}  EXCLUDE_FROM_ALL ${x}/${x}.c)
@@ -17,7 +17,7 @@ set(tesh_files    ${tesh_files}    PARENT_SCOPE)
 set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/dht-pastry/dht-pastry_d.xml                 PARENT_SCOPE)
 
 if(enable_msg)
-  foreach(x dht-pastry synchro-semaphore)
+  foreach(x dht-pastry)
     ADD_TESH_FACTORIES(msg-${x} "thread;ucontext;raw;boost" 
                                 --setenv bindir=${CMAKE_BINARY_DIR}/examples/deprecated/msg/${x}
                                 --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg/${x} 
diff --git a/examples/deprecated/msg/synchro-semaphore/synchro-semaphore.c b/examples/deprecated/msg/synchro-semaphore/synchro-semaphore.c
deleted file mode 100644 (file)
index c85973b..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Copyright (c) 2013-2020. 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 "simgrid/msg.h"
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example, "Messages specific for this msg example");
-
-msg_sem_t sem;
-
-static int peer(int argc, char* argv[]){
-  int i = 0;
-  while(i < argc) {
-    double wait_time = xbt_str_parse_double(argv[i],"Invalid wait time: %s");
-    i++;
-    MSG_process_sleep(wait_time);
-    XBT_INFO("Trying to acquire %d", i);
-    MSG_sem_acquire(sem);
-    XBT_INFO("Acquired %d", i);
-
-    wait_time = xbt_str_parse_double(argv[i], "Invalid wait time: %s");
-    i++;
-    MSG_process_sleep(wait_time);
-    XBT_INFO("Releasing %d", i);
-    MSG_sem_release(sem);
-    XBT_INFO("Released %d", i);
-  }
-  MSG_process_sleep(50);
-  XBT_INFO("Done");
-
-  return 0;
-}
-
-int main(int argc, char* argv[])
-{
-  MSG_init(&argc, argv);
-  MSG_create_environment(argv[1]);
-
-  msg_host_t h = MSG_host_by_name("Fafard");
-
-  sem = MSG_sem_init(1);
-  char** aliceTimes = xbt_new(char*, 9);
-  aliceTimes[0] = xbt_strdup("0");
-  aliceTimes[1] = xbt_strdup("1");
-  aliceTimes[2] = xbt_strdup("3");
-  aliceTimes[3] = xbt_strdup("5");
-  aliceTimes[4] = xbt_strdup("1");
-  aliceTimes[5] = xbt_strdup("2");
-  aliceTimes[6] = xbt_strdup("5");
-  aliceTimes[7] = xbt_strdup("0");
-  aliceTimes[8] = NULL;
-
-  char** bobTimes = xbt_new(char*, 9);
-  bobTimes[0] = xbt_strdup("0.9");
-  bobTimes[1] = xbt_strdup("1");
-  bobTimes[2] = xbt_strdup("1");
-  bobTimes[3] = xbt_strdup("2");
-  bobTimes[4] = xbt_strdup("2");
-  bobTimes[5] = xbt_strdup("0");
-  bobTimes[6] = xbt_strdup("0");
-  bobTimes[7] = xbt_strdup("5");
-  bobTimes[8] = NULL;
-
-  MSG_process_create_with_arguments("Alice", peer, NULL, h, 8, aliceTimes);
-  MSG_process_create_with_arguments("Bob", peer, NULL, h, 8, bobTimes);
-
-  msg_error_t res = MSG_main();
-  MSG_sem_destroy(sem);
-  XBT_INFO("Finished\n");
-  return (res != MSG_OK);
-}