multithreading - Is there an advantage of recycling threads -
in c++, want create algorithms following structure:
- a sequential part
- a parallel part a
- a sequential part
- a parallel part b
- a sequential part
using pthreads, can think of 2 ways solve problem:
- create n threads part , destructing these threads after part finished. allocating n new threads part b.
- using same threads part , part b using various kinds of synchronization methods available.
how overhead take create new threads solution 1 when performance matters. should go solution 1 or solution 2?
parallel frameworks such openmp recycle threads. called thread pool, , can find information on site. here's 1 related post: thread pool vs thread spawning
if you're concerned performance, best way find out suits application try both approaches , measure them.
in general, if processing task expensive , code easier understand if spawn new threads, that.
and colour argument little, check out post answered using experimentation other day: why 50 threads faster 4?
Comments
Post a Comment