Greetings. I'm just about to code my project using multhithreading. But before jumping into that, I ran into this article http://doc.trolltech.com/4.2/threads.html which made me think twice about the parallel structure that I initially planned.
The original plan was to create 2 threads: one producer and one consumer thread. The producer thread will acquire data and place it in a buffer then start acquiring the next data. The consumer thread then gets data from the buffer and does the processing. Both of these threads run infinitely and are only controlled using the GUI buttons - start and stop.
I'm using 2 CPUs in my desktop. Now, the fact that I would have to keep my GUI responsive (due to the threads continuously processing data) I will have to have a main thread for my button controls. So all in all, I should be using 3 threads right? Or am I wrong?
Just in case three, will this slow my processes down with the overhead of virtually maintaining an additional thread with only 2 physical cores?


Reply With Quote

But indeed going for three threads is the simplest solution. If you have two threads or three threads it doesn't really matter in terms of speed. It is so because there are other processes running on your system too and they occupy the cores as well so context switching is present if you have one thread, two threads or three - your process simply has to share the cores with all other processes.


Bookmarks