Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Employee
40 Views

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

#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
Highlighted
Employee
40 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.htm...

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