Hi to all,
i'm developing a multi-threaded application and i'm here to ask for a little help :) As i don't have much experience in multi-threading, especially in win32 API and this is my very first experience with it, i just wanted to check if I'm on the right way with my abstract model. I have read a reasonable amount of literature before posting this question, such as almost entire Multi-Threading Applications in Win32 book and number of internet articles.
Let me explain thoroughly what this application is really about. Complete system is really consisted of two parts:
- windows application that is needed to develop
- external hardware that is measuring some data by using Silabs micro-controller
They communicate each other by USB protocol and drivers are not a problem as they're already delivered by Silabs. The one i am supposed to do is that application part.
So, my application should do the following tasks simultaneously:
- Show some images on a form (just like a slideshow in windows).
- Receive measured data from USB device. This resulting data is dependent of a previous step as the test is being executed on a human being.
- Do some data analysis.
- Plot analyzed data.
As you can see that's a lot of work to do in a single thread. That's why i decided to put a little bit more effort and make this tasks execute "concurrently". But i realized it's not that easy and that's why i'm here.
My thought was to potentially have the following threads/parts:
- GUI thread for manipulating user interface. This would be primary thread as well.
- Thread which would take care of making an image slideshow.
- Thread for listening to a data on a USB port.
- Thread for analyzing data.
- Thread for plotting data.
For the italic ones i'm still not quite sure if it is really necessary to place them into a dedicated thread. I was thinking to move them into the first thread, responsible for GUI. I had in mind to have some event handlers in the primary thread in which i could capture data from USB and straightaway analyze it and plot it onto the canvas. Analysis shouldn't be very time consuming.
Also I would use user defined messages (i.e. with PostThreadMessage()
) to signalize the GUI from USB thread that the data has arrived and in that way trigger data analysis and plotting.
One more detail that is making me concerned is that slideshow thread. I've read that it's not possible/advisable to change GUI from another thread. So what do you think the solution could be in this case? To put it in the same GUI thread (that seems to me as a overkill for a GUI thread) or again handle it in the main thread with some kind of a event?
So, my question would be what do you generally think about this concept? Is there a better/more flexible/easier way to do it?
Thanks guys,
Adi
P.S. i'm using c++ within C++ Builder 2009 IDE