mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Change lock mechanism to std::lock_guard
This commit is contained in:
parent
4d0179cffc
commit
c73a51650f
@ -51,9 +51,8 @@ public:
|
|||||||
{
|
{
|
||||||
assert(0 <= runner->workerThreadIndex() && runner->workerThreadIndex() < runner->numWorkerThreads());
|
assert(0 <= runner->workerThreadIndex() && runner->workerThreadIndex() < runner->numWorkerThreads());
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(mseconds_));
|
std::this_thread::sleep_for(std::chrono::milliseconds(mseconds_));
|
||||||
outputMutex.lock();
|
std::lock_guard<std::mutex> guard(outputMutex);
|
||||||
std::cout << "Sleep tasklet " << n_ << " of " << mseconds_ << " ms completed by worker thread " << runner->workerThreadIndex() << std::endl;
|
std::cout << "Sleep tasklet " << n_ << " of " << mseconds_ << " ms completed by worker thread " << runner->workerThreadIndex() << std::endl;
|
||||||
outputMutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -67,9 +66,8 @@ void sleepAndPrintFunction()
|
|||||||
{
|
{
|
||||||
int ms = 100;
|
int ms = 100;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
||||||
outputMutex.lock();
|
std::lock_guard<std::mutex> guard(outputMutex);
|
||||||
std::cout << "Sleep completed by worker thread " << runner->workerThreadIndex() << std::endl;
|
std::cout << "Sleep completed by worker thread " << runner->workerThreadIndex() << std::endl;
|
||||||
outputMutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int SleepTasklet::numInstantiated_ = 0;
|
int SleepTasklet::numInstantiated_ = 0;
|
||||||
|
@ -58,9 +58,8 @@ public:
|
|||||||
assert(0 <= runner->workerThreadIndex() && runner->workerThreadIndex() < runner->numWorkerThreads());
|
assert(0 <= runner->workerThreadIndex() && runner->workerThreadIndex() < runner->numWorkerThreads());
|
||||||
std::cout << "Sleep tasklet " << id_ << " of " << mseconds_ << " ms starting sleep on worker thread " << runner->workerThreadIndex() << std::endl;
|
std::cout << "Sleep tasklet " << id_ << " of " << mseconds_ << " ms starting sleep on worker thread " << runner->workerThreadIndex() << std::endl;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(mseconds_));
|
std::this_thread::sleep_for(std::chrono::milliseconds(mseconds_));
|
||||||
outputMutex.lock();
|
std::lock_guard<std::mutex> guard(outputMutex);
|
||||||
std::cout << "Sleep tasklet " << id_ << " of " << mseconds_ << " ms completed by worker thread " << runner->workerThreadIndex() << std::endl;
|
std::cout << "Sleep tasklet " << id_ << " of " << mseconds_ << " ms completed by worker thread " << runner->workerThreadIndex() << std::endl;
|
||||||
outputMutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -77,9 +76,8 @@ public:
|
|||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(mseconds_));
|
std::this_thread::sleep_for(std::chrono::milliseconds(mseconds_));
|
||||||
outputMutex.lock();
|
std::lock_guard<std::mutex> guard(outputMutex);
|
||||||
std::cout << "Failing sleep tasklet of " << mseconds_ << " ms failing now, on work thread " << runner->workerThreadIndex() << std::endl;
|
std::cout << "Failing sleep tasklet of " << mseconds_ << " ms failing now, on work thread " << runner->workerThreadIndex() << std::endl;
|
||||||
outputMutex.unlock();
|
|
||||||
throw std::logic_error("Intentional failure for testing");
|
throw std::logic_error("Intentional failure for testing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user