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.
This commit is contained in:
Andreas Lauser 2018-04-23 13:16:40 +02:00
parent 5c9e20c00e
commit 25e952fb49

View File

@ -33,6 +33,8 @@
#include <chrono>
#include <iostream>
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: