mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Change pointer to tasklet runners to smart pointer and add comment about why they are created on the heap
This commit is contained in:
@@ -35,7 +35,8 @@
|
||||
|
||||
std::mutex outputMutex;
|
||||
|
||||
Opm::TaskletRunner *runner;
|
||||
// The runner is created on the heap for the assertion and outputs in the run function of the tasklets.
|
||||
std::unique_ptr<Opm::TaskletRunner> runner{};
|
||||
|
||||
class SleepTasklet : public Opm::TaskletInterface
|
||||
{
|
||||
@@ -75,7 +76,7 @@ int SleepTasklet::numInstantiated_ = 0;
|
||||
int main()
|
||||
{
|
||||
int numWorkers = 2;
|
||||
runner = new Opm::TaskletRunner(numWorkers);
|
||||
runner = std::make_unique<Opm::TaskletRunner>(numWorkers);
|
||||
|
||||
// the master thread is not a worker thread
|
||||
assert(runner->workerThreadIndex() < 0);
|
||||
@@ -94,8 +95,6 @@ int main()
|
||||
runner->dispatchFunction(sleepAndPrintFunction);
|
||||
runner->dispatchFunction(sleepAndPrintFunction, /*numInvokations=*/6);
|
||||
|
||||
delete runner;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@
|
||||
|
||||
std::mutex outputMutex;
|
||||
|
||||
Opm::TaskletRunner *runner;
|
||||
// The runner is created on the heap for the assertion and outputs in the run function of the tasklets.
|
||||
std::unique_ptr<Opm::TaskletRunner> runner{};
|
||||
|
||||
class SleepTasklet : public Opm::TaskletInterface
|
||||
{
|
||||
@@ -87,7 +88,7 @@ private:
|
||||
|
||||
void execute () {
|
||||
int numWorkers = 2;
|
||||
runner = new Opm::TaskletRunner(numWorkers);
|
||||
runner = std::make_unique<Opm::TaskletRunner>(numWorkers);
|
||||
|
||||
// the master thread is not a worker thread
|
||||
assert(runner->workerThreadIndex() < 0);
|
||||
|
||||
Reference in New Issue
Block a user