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

Thread has not activated a task_scheduler_init object

eyalk
Beginner
504 Views

In my application run several regular windows threads. 2 of these threads create in thier constructor 2 task scheduler object (each one of them has one task scheduler object).
Iuse the parallel_for function in several places in my application.The useis only on the above 2 threads.
Sometimes i get the following message (probably during the activation of the first parallel_for). Can you guess why it happans? what could fix this problem?

The specific error is
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: ...
Module: tbb_debug.dll
File: ../../src/tbb/task.cpp
Line: 3113

Expression: my_owner

Thread has not activated a task_scheduler_init object?

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)


Thank you.

0 Kudos
5 Replies
pvonkaenel
New Contributor III
504 Views

In my application run several regular windows threads. 2 of these threads create in thier constructor 2 task scheduler object (each one of them has one task scheduler object).
Iuse the parallel_for function in several places in my application.The useis only on the above 2 threads.
Sometimes i get the following message (probably during the activation of the first parallel_for). Can you guess why it happans? what could fix this problem?

The specific error is
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: ...
Module: tbb_debug.dll
File: ../../src/tbb/task.cpp
Line: 3113

Expression: my_owner

Thread has not activated a task_scheduler_init object?

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)


Thank you.


As long as each of your Win32 threads has created it's own instance of a tbb::task_scheduler_init, you should be OK. That brings me to a couple of stupid questions about how your code is structured:

1) What are you passing into the task_scheduler_init constructor? Are you defering initialization and then forgetting to initialize?

2) Does each thread have it's own instance of a task_scheduler_init? It will not work if they are sharing a single instance (at least as far as I know).

3) Are you using local task_scheduler_init instances within your class constructors? If so, they will be destructed when your constructor completes. The best thing to do is have a private/protected task_scheduler_init class instance in your class which is initialized in your constructor, and terminated in your destructor.

You're probably not doing any of these, but hopefully they will give you some ideas of what to look for.

Peter
0 Kudos
eyalk
Beginner
504 Views
Quoting - pvonkaenel

As long as each of your Win32 threads has created it's own instance of a tbb::task_scheduler_init, you should be OK. That brings me to a couple of stupid questions about how your code is structured:

1) What are you passing into the task_scheduler_init constructor? Are you defering initialization and then forgetting to initialize?

2) Does each thread have it's own instance of a task_scheduler_init? It will not work if they are sharing a single instance (at least as far as I know).

3) Are you using local task_scheduler_init instances within your class constructors? If so, they will be destructed when your constructor completes. The best thing to do is have a private/protected task_scheduler_init class instance in your class which is initialized in your constructor, and terminated in your destructor.

You're probably not doing any of these, but hopefully they will give you some ideas of what to look for.

Peter

Hi Peter:
I am not doing any of these. As i wote- this error occures not very frequently. Any ideas?

Eyal
0 Kudos
RafSchietekat
Valued Contributor III
504 Views

I assume that, like tbb_thread or any other thread objects that I know, these thread objects are (obviously) not constructed inside the thread that they manage? But you really have to have a task_scheduler_init in that thread itself, so if you want to hide its use, do so in a function that is passed to super, thathas a local/automatic task_scheduler_init on the thread's stack, and that then forwards its arguments to the argument function of the overridden thread object.

If there's anything that by definition qualifies for a new FAQ entry, it's these task_scheduler_init issues... :-)

0 Kudos
Alexey-Kukanov
Employee
504 Views
Hi Peter:
I am not doing any of these. As i wote- this error occures not very frequently. Any ideas?

Eyal

I believe the reason of the issue is no active task_scheduler_init object in the thread attempting to execute a parallel algorithm. It's hard to say why it may be so, without seeing your code.
However mitigation can be simple - just create an additional task_scheduler_init object locally in the function that calls a TBB algorithm. If the thread was already set up to use TBB, the additional cost is very low. Otherwise, the required thread local structures will be created, giving you the desired remedy. Most likely, the thread pool already exists; andit will not be (re)created in this case.

In a coming-soon next version of TBB, such "lazy" initialization will be performed automatically.
0 Kudos
pvonkaenel
New Contributor III
504 Views

Hi Peter:
I am not doing any of these. As i wote- this error occures not very frequently. Any ideas?

Eyal

As I said, I thought you probably avoided these simple errors, but without seeing any code it's really hard to guess what your problem is.
0 Kudos
Reply