Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #244 from Takishipp/actor-yield
[simgrid.git] / teshsuite / s4u / concurrent_rw / concurrent_rw.cpp
index 82a0ca8..0c1db3c 100644 (file)
@@ -1,42 +1,30 @@
-/* Copyright (c) 2008-2010, 2012-2015, 2017. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2008-2017. 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/s4u.hpp"
-#include <unistd.h>
-
-#define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u test");
 
 static void host()
 {
-  char name[2048];
-  int id = simgrid::s4u::this_actor::pid();
-  snprintf(name, 2048, "%s%i", FILENAME1, id);
-  simgrid::s4u::File* file = new simgrid::s4u::File(name, NULL);
+  simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk1");
+  int id = simgrid::s4u::this_actor::getPid();
   XBT_INFO("process %d is writing!", id);
-  file->write(3000000);
+  storage->write(3000000);
   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
   simgrid::s4u::this_actor::sleep_for(id);
   XBT_INFO("process %d is writing again!", id);
-  file->write(3000000);
+  storage->write(3000000);
   XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id);
   simgrid::s4u::this_actor::sleep_for(6 - id);
   XBT_INFO("process %d is reading!", id);
-  file->seek(0);
-  file->read(3000000);
+  storage->read(3000000);
   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
   simgrid::s4u::this_actor::sleep_for(id);
   XBT_INFO("process %d is reading again!", id);
-  file->seek(0);
-  file->read(3000000);
-
-  XBT_INFO("process %d => Size of %s: %llu", id, name, file->size());
-  // Close the file
-  delete file;
+  storage->read(3000000);
 }
 
 int main(int argc, char** argv)
@@ -50,5 +38,6 @@ int main(int argc, char** argv)
   e->run();
   XBT_INFO("Simulation time %g", e->getClock());
 
+  delete e;
   return 0;
 }