1 /* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved. */
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. */
6 // This example implements a simple producer/consumer schema,
7 // passing a bunch of items from one to the other
9 #include "simgrid/s4u.hpp"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
15 const char* buffer; /* Where the data is exchanged */
16 simgrid::s4u::SemaphorePtr sem_empty = simgrid::s4u::Semaphore::create(1); /* indicates whether the buffer is empty */
17 simgrid::s4u::SemaphorePtr sem_full = simgrid::s4u::Semaphore::create(0); /* indicates whether the buffer is full */
20 static void producer(std::vector<std::string>* args)
22 for (auto str : *args) {
24 XBT_INFO("Pushing '%s'", str.c_str());
31 static void consumer()
37 XBT_INFO("Receiving '%s'", str.c_str());
44 int main(int argc, char **argv)
46 std::vector<std::string> args = std::vector<std::string>({"one", "two", "three", ""});
47 simgrid::s4u::Engine e(&argc, argv);
48 e.load_platform("../../platforms/two_hosts.xml");
49 simgrid::s4u::Actor::create("producer", simgrid::s4u::Host::by_name("Tremblay"), producer, &args);
50 simgrid::s4u::Actor::create("consumer", simgrid::s4u::Host::by_name("Jupiter"), consumer);