1. Can I use TBB in hard-real time applications ? (if the answer is no, please explain why ?)
2. Can I use TBB in soft-real time applications ? (if the answer is no, please explain why ?)
It is very importent to explain why or why not.
Intel Threading Building Blocks uses a unfair scheduler for assigning tasks to threads: any thread can choose on completion of a task what task to perform next, the purpose being to keep related tasks on the same HW threads to preserve any working data in the local caches to reuse rather than having to write changes back to memory and read them into a different HW thread. Given such a scheduler, it may not be possible to offer real-time response guarantees, hard or soft.
You could use something like task-scheduler-observer to set thread affinities and lock specific TBB worker threads to particular HW threads. That still doesn't provide any means to guarantee that a new task will be initiated within a guaranteed interval. The way work propagates across the worker threads in the scheduler is through task stealing, wherein an idle Intel TBB worker randomly selects other workers looking for work to steal, taking unstarted tasks from a different worker's work queue. Random search for schedulable work is not a very reliable method on which to base a real-time scheduling guarantee.