PDA

View Full Version : consuming thread usage.



wagmare
4th February 2013, 09:13
Hi friends,

Im working in a networking project with GUI ..

This is my scenario ..
Im receiving two different data say server1, server2,

server 1 running as udp so to receive i use one QThread thread1,
server 2 running as Multicast so to receive i use one QThread thread2

and i need to map the both value and perform some calculation so i used another seperate thread thread3 to receive both the data simultaneously without interupping GUI ..

is there any other good way as i can conserve the usage of thread .. ?
any other stuff like QConcurrent or other things i can deploy in later ..?


Please help me

Thanks in advance ..

wysota
4th February 2013, 09:20
You can not use threads at all. The GUI thread is enough to do all the tasks.

Santosh Reddy
4th February 2013, 09:23
Is you question about how to avoid threads?

wagmare
4th February 2013, 09:36
You can not use threads at all. The GUI thread is enough to do all the tasks.

first thanks for the reply wysota :)
but how i can receive two different data at a same time in a loop .. from server one and two synchronously ... and display those two datas in a table ..


Is you question about how to avoid threads?

Thanks for the reply reddy ..
yes ..
i want to reduce the thread usage ...

wysota
4th February 2013, 09:40
but how i can receive two different data at a same time in a loop .. from server one and two synchronously ... and display those two datas in a table ..
Use signals and slots. You don't need any loops. When one socket signals it has data ready, read it, store it, check if the other socket already received the data you need and if not then return. Do the same for the other socket. If both sockets already received their data, emit a signal that both are ready and in a slot connected to that signal read the stored data and process it. The latter can be done in an external thread (e.g. using QtConcurrent::run()) if processing is computation intensive.

wagmare
4th February 2013, 10:09
The latter can be done in an external thread (e.g. using QtConcurrent::run()) if processing is computation intensive

Thx wysota ..
yes .. the computation is intense ..
Can u explain me why i should go for QConcurrent ..specifically ..and not normal QThread::run() ..?

wysota
4th February 2013, 10:35
There are several reasons. If the computation can be enclosed in a single function then using Qt Concurrent is like calling that single function where you can pass arguments directly and obtain a deferred result through the use of QFuture. With QFutureWatcher you can be notified when the computation is complete. Furthermore Qt Concurrent will spawn only as many threads as there are cores available which allows to handle a situation where data bursts in faster than it can be processed. With a regular QThread You would have to either spawna a new thread for each incoming data which is a straight way to DOS or you would have to queue requests and synchronise the thread. In short if you can use Qt Concurrent, it is usually easier than implementing your own thread.

wagmare
4th February 2013, 11:22
Well explained ... thank you Wysota ..