Sometimes the loop control is spread across complex control flow. Using Intel TBB or Intel Cilk Plus in this situation requires more features than the simple loops. Note that the task body must not access any of the auto variables defined within the annotation site, because they may have been destroyed before or while the task is running. Consider this serial code:
You can enable multiple functions to run in parallel as two or more tasks. The statements to run in parallel are not limited to function calls (see the help topic Data and Task Parallelism).
When the outermost statements in the annotation site have been placed into tasks, as shown in the following serial example, it is easy to execute them in parallel.
After you have added locks, but before adding the constructs that cause the program to use parallel execution, you should test your serial program. The locking code may introduce problems if you have inadvertently used a non-recursive mutex in a recursive context, or if your edits accidentally changed some other piece of program behavior.