Hi all! I am in a process of fixing the resource usage of my app, since right now it is an outright "system resource hog." This is due to fact that my pthread has an infinite loop constantly checking elapsed time, so that it can accordingly update the gui display of the timer (chrono-like display). In order to fix this I've tried 2 approaches:
1) I tried changing over to Qthreads, but the problem is whenever I declare a new clas: class foo : public QThread this yields syntax error due to QThread (if it is any other qt class, this line reports no syntax error. What is wrong wit this? I am using MDK 8.1 with Kdevelop 2.0 and qt 2.2 or 2.3 (whichever came packaged with the MDK 8.1), and there is QThread annotated in the qt docs, and even the example code contained in the docs yields the same compile error. Could it be that I should do ./configure --enable-mt in order for my code to compile properly? So this option right now remains to be explored, but since I am in a time crunch and I chose option 2 (described below) after being stuck at this one, I am looking for a possible solution to my problem using pthreads, also since I will have to use the similar method regardless of which type of thread I use. 2) I am using pthread_create right now (everything works), but since the loop within the thread is infinite, it poses as a serious resource hog. So, what I decided to do is to add usleep(10000) value which would give me 10ms sleep "sessions" in between the counting, since my timer only uses two decimal points for subdivisions of the second. But whenever I do this and compile the program, the application's timer runs SLOWER, no matter what is the usleep value (even if it is 1!), and only speeds up to what it is supposed to be when I move/wiggle the mouse over the main app's widget, and/or click with the mouse. Why the heck is this happening? It is obvious that the usleep() is causing this kind of unusual behavior in combination with the qt gui, but why, that is a mystery to me. Is there a more elegant way of making the pthread sleep using sub-second time values? Can someone explain why is this the case? It seems almost that due to fact that there are no events coming from the mouse/keyboard, the qt-gui app is being bogged down by the utilization of usleep. If this is the case, can I somehow force fake events onto the gui in order to make sure that the app runs smoothly? Changing the pthread priority to SCHED_RR or SCHED_FIFO did not fix this problem either. I would greatly appreciate any help I can get on this issue. Thank you! Sincerely, Ivica Bukvic
