From 25e952fb493ceddce89ac314b9e7e0ca521b160f Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Mon, 23 Apr 2018 13:16:40 +0200 Subject: [PATCH] tasklets test: guard against garbled output Use a mutex to ensures that only a single prints at the same time. this should prevent garbled terminal output and thus makes the it much easier to read. on the flipside, some race conditions may go unnoticed. --- tests/models/test_tasklets.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/models/test_tasklets.cpp b/tests/models/test_tasklets.cpp index 31892d2ba..6b8dffb70 100644 --- a/tests/models/test_tasklets.cpp +++ b/tests/models/test_tasklets.cpp @@ -33,6 +33,8 @@ #include #include +std::mutex outputMutex; + Ewoms::TaskletRunner *runner; class SleepTasklet : public Ewoms::TaskletInterface @@ -49,7 +51,9 @@ public: { assert(0 <= runner->workerThreadIndex() && runner->workerThreadIndex() < runner->numWorkerThreads()); std::this_thread::sleep_for(std::chrono::milliseconds(mseconds_)); + outputMutex.lock(); std::cout << "Sleep tasklet " << n_ << " of " << mseconds_ << " ms completed by worker thread " << runner->workerThreadIndex() << std::endl; + outputMutex.unlock(); } private: