3.8 static vs dynamic thread management QT provides a pool of threads, applications gain performance by reusing threads When a thread is needed, an idle thread is selected from the pool This is more efficient even though thread creation is orders of magnitude faster than process creation, thread creation still takes time. Example listing 3.25
Creating and Managing a pool of threads REQUIREMENTS Be able to describe computational tasks Communicate computational tasks Identify threads that are executing a task Signal the termination of a task’s execution
3.9Debugging Multithreaded Applications GDB and DDD (data display debugger, a front end to GDB or DBX) Compile with –g Often time sensitive affected by the debugger
Steps to ensure bug free applications Don’t introduce bugs Write bug free code Use a good design Use previously written programs adapted to specific application Create a log of programs execution Allow the threads to be variable Debugging 1 thread is easier than 10, 2 or 3 also easier
Printf or Cout Typically not sufficient Output is intermixed via the threads Can write to a file myprog 2> trace.log Use a high resolution timer to time stamp messages #define DEBUG #ifdef DEBUG ……… #endif
More debugging hints Disable compiler optimizations An optimization can (rarely) introduce bugs
Many example programs Qthreads Openmp MPI GPU