X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/093776b9da6272771c04f848d9bd5ee28f5e06e3..18e10c8748bc9c49dadbb9f59d188614f5ac196f:/examples/s4u/io-async/s4u-io-async.cpp diff --git a/examples/s4u/io-async/s4u-io-async.cpp b/examples/s4u/io-async/s4u-io-async.cpp index 597284fcc9..86a2358d47 100644 --- a/examples/s4u/io-async/s4u-io-async.cpp +++ b/examples/s4u/io-async/s4u-io-async.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-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. */ @@ -19,9 +19,25 @@ static void test(sg_size_t size) XBT_INFO("Goodbye now!"); } +static void test_waitfor(sg_size_t size) +{ + simgrid::s4u::Disk* disk = simgrid::s4u::Host::current()->get_disks().front(); + XBT_INFO("Hello! write %llu bytes from %s", size, disk->get_cname()); + + simgrid::s4u::IoPtr activity = disk->write_async(size); + try { + activity->wait_for(0.5); + } catch (const simgrid::TimeoutException&) { + XBT_INFO("Asynchronous write: Timeout!"); + } + + XBT_INFO("Goodbye now!"); +} + static void test_cancel(sg_size_t size) { simgrid::s4u::Disk* disk = simgrid::s4u::Host::current()->get_disks().front(); + simgrid::s4u::this_actor::sleep_for(0.5); XBT_INFO("Hello! write %llu bytes from %s", size, disk->get_cname()); simgrid::s4u::IoPtr activity = disk->write_async(size); @@ -32,12 +48,29 @@ static void test_cancel(sg_size_t size) XBT_INFO("Goodbye now!"); } +static void test_monitor(sg_size_t size) +{ + simgrid::s4u::Disk* disk = simgrid::s4u::Host::current()->get_disks().front(); + simgrid::s4u::this_actor::sleep_for(1); + simgrid::s4u::IoPtr activity = disk->write_async(size); + + while (not activity->test()) { + XBT_INFO("Remaining amount of bytes to write: %g", activity->get_remaining()); + simgrid::s4u::this_actor::sleep_for(0.2); + } + activity->wait(); + + XBT_INFO("Goodbye now!"); +} + int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); e.load_platform(argv[1]); simgrid::s4u::Actor::create("test", simgrid::s4u::Host::by_name("bob"), test, 2e7); + simgrid::s4u::Actor::create("test_waitfor", simgrid::s4u::Host::by_name("alice"), test_waitfor, 5e7); simgrid::s4u::Actor::create("test_cancel", simgrid::s4u::Host::by_name("alice"), test_cancel, 5e7); + simgrid::s4u::Actor::create("test_monitor", simgrid::s4u::Host::by_name("alice"), test_monitor, 5e7); e.run();