I understand that threading is needed to get the maximum performance out of today's multicore processors but starting a thread is rather costly so you can't put every single calculation that can be done in parallel in an own thread. For example
answer = new thread(plus(1,2)) + new thread(plus(3,4))
will run much slower than the simple single-threaded
answer = 1+2+3+4
but if plus was some really complicated calculation the threaded variant might be faster.
Now to the questions
- Are there any convention or standards about what the minimum length of code, operations or execution time that are defendable to put in its own thread?
- Do I even have to worry about this or are the compiler/processor so smart that they do all the work for me?
The reason I ask this question is that I saw an implementation of quicksort that started a new thread for every recursive call ending up with (n²) threads and there many of this threads just returned some value.