Change pointer to tasklet runners to smart pointer and add comment about why they are created on the heap

This commit is contained in:
Lisa Julia Nebel
2024-07-15 14:24:32 +02:00
parent c73a51650f
commit 0a70296eb9
2 changed files with 6 additions and 6 deletions

View File

@@ -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;
}

View File

@@ -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);