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

tbb::task::enqueue causes SEGFAULT

palodequeso
Beginner
417 Views

I am writing a resource manager class for my game engine. I want it to run outside of the normal task queue completely in parallel (as if it were a normal thread). I know I could just make a std::thread but after reading this post: http://stackoverflow.com/questions/8301827/using-tbb-for-non-parallel-tasks I figured I could just create a task and pass it to tbb::task::enqueue and inside it's execute method I could just have it loop forever (until there's a quit condition). This is also referred to in the GUI section of the docs. But when I call tbb::task::enqueue I get a SEGFAULT. Here's a traceback:

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7bc23e7 in tbb::task::enqueue (t=...) at /usr/include/tbb/task.h:720 720 t.prefix().owner->enqueue( t, NULL ); (gdb) backtrace #0 0x00007ffff7bc23e7 in tbb::task::enqueue (t=...) at /usr/include/tbb/task.h:720 #1 0x00007ffff7bc15ab in DS::Core::Scheduler::Start (this=0x603f60) at /home/dougr/.projects/deepspaceengine/engine/core/source/scheduler.cpp:31 #2 0x00007ffff7bc0e2e in DS::Application::Application::Run (this=0x7fffffffdcf0) at /home/dougr/.projects/deepspaceengine/engine/application/source/application.cpp:32 #3 0x0000000000400cc9 in main (argc=1, argv=0x7fffffffde18) at /home/dougr/.projects/deepspaceengine/applications/tests/base.cpp:5

From this it seems that owner is NULL or 0. Do I have to do something more than just what the stack overflow article says? Is there a better approach to this in general?

I'm on Ubuntu 13.04 with libtbb-dev version 4.0+r233-1

Thanks for the help!

PS: I'd be happy to post any code, it's not any special license or sensitive.

0 Kudos
1 Reply
palodequeso
Beginner
417 Views

[EDIT] It's definitely something in my code because this simple example works fine:

#include <tbb/tbb.h>
#include <iostream>

class MyTask : public tbb::task {
    public:
        tbb::task *execute(void) {
            std::cout << "Test Execute" << std::endl;
            return NULL;
        }
};

int main(int argc, char **argv) {
    MyTask* t = new (tbb::task::allocate_root()) MyTask();
    tbb::task::enqueue(*t);

    while (true) {
        //
    }

    return 0;
}

compiled with g++ main.cpp --std=c++11 -ltbb -o test.o

That works just fine

0 Kudos
Reply