i use QTimer before but its get so cpu usage for 50 msec call, am i right? this program run on a embedded system
and how can i handle download thread?
i use QTimer before but its get so cpu usage for 50 msec call, am i right? this program run on a embedded system
and how can i handle download thread?
If you use a thread it will also bump up your cpu usage. If you need to do something, it will have to be done by the cpu regardless if you use a thread or not.
i dont mean that, i mean impletation of Qtimer for small intervals may be is not so good i dont remember where i read this so i ask,
and if i use a timer for my main loop how can i run a task thread for downloading and uploading my data?
you say a timer exactly run in its interval time and sleep other threads? ( i think timeout signal go to queue so my other threads can delay running main process)
Last edited by danics; 13th August 2013 at 15:15.
Ask the one who wrote it
You don't need a thread for that.and if i use a timer for my main loop how can i run a task thread for downloading and uploading my data?
The timer has no influence on other threads.you say a timer exactly run in its interval time and sleep other threads?
Look, it is very simple -- if your program has to do two tasks which take 10 and 20 units of the processor time then regardless if you use threads or not, you will have to spend 30 units of processor time on those tasks. If your machine can do more tasks in parallel than there are tasks waiting to execute (e.g. the processor has multiple cores) then the real time used to complete both tasks (assuming they are independent) will take less than 30 units of time. If your machine has less concurrent threads than there are tasks to execute then the total amount of time spent will be more than those 30 units because the processor will need to switch between tasks. Considering the system has to do more than just handle your two-threaded application, it is very likely it has more tasks to do than threads available. In that case adding more and more threads will slow down the process rather than speeding it up.( i think timeout signal go to queue so my other threads can delay running main process)
ok let me explain more, i want to know witch solution is better,
first of all i know i need 30 units, but i have priority for switch task, i need my main thread run with download thread somehow simultaneity but if sleep time of main thread finished the download thread must go to sleep and wait to up until main thread again finish, so in your explanation we cant send a signal to a thread to sleep and call another thread to run, we can do this right? and if you say yes, how much this process better than use timers (in timers mode probably main thread dont run until download thread finish)
we have a loop for main thread and we set a wait condition this is main loop
while(1) {
waitOn(); // check if Ui is in waiting state and if its not set uis and download to wait
doWork();
setOn() // set wait to free
sleep(100);
}
and our problem is download thread, its not run sync so i dont know how implement it?
and finally you dont say if i send my sample download command i a thread object and then call exec() function of that thread everything works in event loop of that thread right?
You don't need any "download thread". It's not that there is a dwarf sitting there and constantly pulling a string that has your incoming data attached to it and which needs constant bugging to get to work. When the data arrives into the socket you will be informed about it, you can read the data (which takes literally miliseconds) and afterwards you can attend to other tasks. When more data arrives, you will again be informed about it, you will read the data and go back to the other task. On the other hand if you do it with threads, your thread will sit around doing nothing 99% of the time and you will have a lot of trouble in synchronizing all your threads.
Your while() loop can be decomposed into a simple timer running with 100ms interval that triggers a slot that calls "doWork()".
Here, read this: [wiki]Keeping the GUI Responsive[/wiki]
danics (14th August 2013)
Bookmarks