Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / s4u / concurrent_rw / concurrent_rw.cpp
1 /* Copyright (c) 2008-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u.hpp"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u test");
9
10 static void host()
11 {
12   simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk1");
13   int id = simgrid::s4u::this_actor::getPid();
14   XBT_INFO("process %d is writing!", id);
15   storage->write(3000000);
16   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
17   simgrid::s4u::this_actor::sleep_for(id);
18   XBT_INFO("process %d is writing again!", id);
19   storage->write(3000000);
20   XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id);
21   simgrid::s4u::this_actor::sleep_for(6 - id);
22   XBT_INFO("process %d is reading!", id);
23   storage->read(3000000);
24   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
25   simgrid::s4u::this_actor::sleep_for(id);
26   XBT_INFO("process %d is reading again!", id);
27   storage->read(3000000);
28 }
29
30 int main(int argc, char** argv)
31 {
32   simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
33   e->loadPlatform(argv[1]);
34
35   for (int i = 0; i < 5; i++)
36     simgrid::s4u::Actor::createActor("host", simgrid::s4u::Host::by_name("bob"), host);
37
38   e->run();
39   XBT_INFO("Simulation time %g", e->getClock());
40
41   delete e;
42   return 0;
43 }