Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
For Sonar.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 13 Feb 2023 08:49:37 +0000 (09:49 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 13 Feb 2023 13:50:11 +0000 (14:50 +0100)
examples/cpp/network-ns3/s4u-network-ns3.cpp
examples/cpp/synchro-semaphore/s4u-synchro-semaphore.cpp

index a8a7f9d..e1c8b39 100644 (file)
@@ -32,7 +32,7 @@ static void master(MasterWorkerNamesMap& names, const std::vector<std::string>&
   int id          = std::stoi(args[3]); // unique id to control statistics
 
   /* master and worker names */
-  names.emplace(id, MasterWorkerNames{sg4::Host::current()->get_name(), args[2]});
+  names.try_emplace(id, MasterWorkerNames{sg4::Host::current()->get_name(), args[2]});
 
   sg4::Mailbox* mbox = sg4::Mailbox::by_name(args[3]);
 
index 4040407..b9b5e77 100644 (file)
@@ -14,24 +14,24 @@ namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(sem_test, "Simple test of the semaphore");
 
-static void producer(std::string& buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full,
+static void producer(std::string* buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full,
                      const std::vector<std::string>& args)
 {
   for (auto const& str : args) {
     sem_empty->acquire();
     XBT_INFO("Pushing '%s'", str.c_str());
-    buffer = str;
+    *buffer = str;
     sem_full->release();
   }
 
   XBT_INFO("Bye!");
 }
-static void consumer(const std::string& buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full)
+static void consumer(const std::string* buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full)
 {
   std::string str;
   do {
     sem_full->acquire();
-    str = buffer;
+    str = *buffer;
     XBT_INFO("Receiving '%s'", str.c_str());
     sem_empty->release();
   } while (str != "");
@@ -49,9 +49,8 @@ int main(int argc, char **argv)
   auto sem_empty = sg4::Semaphore::create(1); /* indicates whether the buffer is empty */
   auto sem_full  = sg4::Semaphore::create(0); /* indicates whether the buffer is full */
 
-  sg4::Actor::create("producer", e.host_by_name("Tremblay"), producer, std::ref(buffer), sem_empty, sem_full,
-                     std::cref(args));
-  sg4::Actor::create("consumer", e.host_by_name("Jupiter"), consumer, std::cref(buffer), sem_empty, sem_full);
+  sg4::Actor::create("producer", e.host_by_name("Tremblay"), producer, &buffer, sem_empty, sem_full, std::cref(args));
+  sg4::Actor::create("consumer", e.host_by_name("Jupiter"), consumer, &buffer, sem_empty, sem_full);
   e.run();
 
   return 0;