PDA

View Full Version : Any Multithreading specialist?



zdnenekkrejci
10th April 2010, 15:14
Hi I just have start with QT just to make a oscilloscope program for my micro-controller. The program should read continuously port and displaying values on the screen,so first I tried with just one,the main thread but as predicted it was just freezing.
OK so I have now one special thread just for this.

There is two buffers of size 500.
One semaphor that is directing whether one or the other buffer can read main or second thread.

So the main thread is just keep checking in a timer body the semaphore whether it can read the first buffer.During that the second thread basically continuously reading port and putting values into that first of two buffers of 500 integers so when this first buffer is full semaphore sets one as "ok buffer full". So now the main thread able to read the first buffer into screen. And so on... that sound good to me maeby any other ideas?
Anyway the main problem is that the timer used by main thread is as it looks sharing the memory with the GUI and all user events to be able make action on user input or other event. So thus I thing it is not smooth process of the timer.And I just need to have quick and smooth timer to display my data from port.
Guys I hope it is clearly explained I would be really happy if someone can help... Thank you verry much

squidge
10th April 2010, 20:52
Why not have two threads - a GUI thread and a communications thread. When the communication thread gets enough buffer it sends a signal to the gui thread "Display this data" and then starts filling in a another buffer. It will repeat indefinitely until told to stop.