Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

task execute sometimes not called

Barak__Carmel
Beginner
323 Views

I'm using Windows 10 64bit with TBB 2018 Update 2.

I have 2 tbb::tasks:

struct QueueProcessingTask : public tbb::task
{
    QueueProcessingTask();
    ~QueueProcessingTask();

    task *execute();
};

struct MainScanTask : public tbb::task
{
    MainScanTask();
    ~MainScanTask();

    task *execute();

    QueueProcessingTask *m_pTask;
};

In my main manager object I have an instance of

MainScanTask *m_mainTask;

And I'm calling

m_mainTask = new(tbb::task::allocate_root()) MainScanTask();
m_mainTask->execute();

where execute is

tbb::task *MainScanTask::execute()
{
    m_pTask = new(allocate_continuation())QueueProcessingTask();
    if (!m_pTask)
    {
        Trace("allocate_continuation() failed");
        return NULL;
    }
    QueueProcessingTask& task1 = *m_pTask;
    Trace("Spawning");
    spawn(task1);
    Trace("Spawned");

    return m_pTask;
}

This part works well. However, once in a while (could be every 10 runs, or could be every 1000 runs), the call to spawn(task1) doesn't seems to call QueueProcessingTask's execute() and therefor causes an access violation on later parts of the run.

I have log prints in which are sometimes not being printed

tbb::task *QueueProcessingTask::execute()
{
    Trace("QueueProcessingTask::execute() 1"); 
    RunPipeLine(); // Launches tbb::pipeline
    Trace("QueueProcessingTask::execute() 2");
    return NULL;
}

My questions are:

  • Why? is there a better way of implementing such mechanism
  • Can I detect such situation and maybe try and spawn again?
0 Kudos
1 Reply
Alexei_K_Intel
Employee
323 Views

Could you explain, what mechanism you are trying to implement, please?

P.S. spawn never calls the execute method, it just publishes the task to be processed by a worker thread.

0 Kudos
Reply