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

How to know that a function is run inside a TBB task

Aharon_A_Intel
Employee
975 Views

#define __TBB_VERSION_STRINGS(N) \
#N": BUILD_HOST        imbeu025 (x86_64)" ENDL \
#N": BUILD_OS        Ubuntu 18.04.2 LTS" ENDL \
#N": BUILD_KERNEL    Linux 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019" ENDL \
#N": BUILD_GCC        g++ (GCC) 7.4.0" ENDL \
#N": BUILD_LIBC    2.27" ENDL \
#N": BUILD_LD        " ENDL \
#N": BUILD_TARGET    intel64 on cc7.4.0_libc2.27_kernel4.15.0" ENDL \

Hello.

I want to use tbb::task::suspend/resume if I'm inside a TBB task and a regular semaphore otherwise. How can I check if the current function is run from inside a TBB task? Is the condition "tbb::task::self().state() == tbb::task::executing" good enough?

0 Kudos
1 Reply
Mark_L_Intel
Moderator
975 Views

According to the documentation it should work -- have you tried this API? Any problems? Can you describe the overall problem that you work on? Just in case, here is a reference to the page that describes how TBB tasking works:

https://www.threadingbuildingblocks.org/docs/help/tbb_userguide/How_Task_Scheduling_Works.html  ;

At the end of the article -- the  short description of Fibonacchi example illustrating the reference counting mechanism 

https://www.threadingbuildingblocks.org/docs/help/tbb_userguide/Simple_Example_Fibonacci_Numbers.html

specifically, using set_ref_count API which also could be used to see if the reference count is zero which would indicate that task is not longer running.

0 Kudos
Reply