A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git]
/
examples
/
cpp
/
synchro-condition-variable-waituntil
/
s4u-synchro-condition-variable-waituntil.cpp
diff --git
a/examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp
b/examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp
index
69ccef1
..
0edd2ab
100644
(file)
--- a/
examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp
+++ b/
examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp
@@
-1,4
+1,4
@@
-/* Copyright (c) 2006-202
2
. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2006-202
3
. 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. */
/* 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. */
@@
-9,15
+9,11
@@
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
namespace sg4 = simgrid::s4u;
-sg4::MutexPtr mtx = nullptr;
-sg4::ConditionVariablePtr cv = nullptr;
-bool ready = false;
-
-static void competitor(int id)
+static void competitor(int id, sg4::ConditionVariablePtr cv, sg4::MutexPtr mtx, std::shared_ptr<bool> ready)
{
XBT_INFO("Entering the race...");
{
XBT_INFO("Entering the race...");
- std::unique_lock
<sg4::Mutex>
lck(*mtx);
- while (not ready) {
+ std::unique_lock lck(*mtx);
+ while (not
*
ready) {
auto now = sg4::Engine::get_clock();
if (cv->wait_until(lck, now + (id+1)*0.25) == std::cv_status::timeout) {
XBT_INFO("Out of wait_until (timeout)");
auto now = sg4::Engine::get_clock();
if (cv->wait_until(lck, now + (id+1)*0.25) == std::cv_status::timeout) {
XBT_INFO("Out of wait_until (timeout)");
@@
-29,25
+25,26
@@
static void competitor(int id)
XBT_INFO("Running!");
}
XBT_INFO("Running!");
}
-static void go()
+static void go(
sg4::ConditionVariablePtr cv, sg4::MutexPtr mtx, std::shared_ptr<bool> ready
)
{
XBT_INFO("Are you ready? ...");
sg4::this_actor::sleep_for(3);
{
XBT_INFO("Are you ready? ...");
sg4::this_actor::sleep_for(3);
- std::unique_lock
<sg4::Mutex>
lck(*mtx);
+ std::unique_lock lck(*mtx);
XBT_INFO("Go go go!");
XBT_INFO("Go go go!");
- ready = true;
+
*
ready = true;
cv->notify_all();
}
static void main_actor()
{
cv->notify_all();
}
static void main_actor()
{
- mtx = sg4::Mutex::create();
- cv = sg4::ConditionVariable::create();
+ auto mtx = sg4::Mutex::create();
+ auto cv = sg4::ConditionVariable::create();
+ auto ready = std::make_shared<bool>(false);
auto host = sg4::this_actor::get_host();
for (int i = 0; i < 10; ++i)
auto host = sg4::this_actor::get_host();
for (int i = 0; i < 10; ++i)
- sg4::Actor::create("competitor", host, competitor, i);
- sg4::Actor::create("go", host, go);
+ sg4::Actor::create("competitor", host, competitor, i
, cv, mtx, ready
);
+ sg4::Actor::create("go", host, go
, cv, mtx, ready
);
}
int main(int argc, char* argv[])
}
int main(int argc, char* argv[])