PDA

View Full Version : QThread under Windows XP - usleep(), msleep() problem



tungstrom
26th July 2009, 16:41
Hello,

in order to control a motor in realtime, i inted to use a separate thread which does the actual work and sleeps with e.g. unsigned long usecs = 1; usleep(usecs);
for a defined number of µseconds to the next cycle.

Regarding the scheduling pattern, i see that it takes typically 7.9 milliseconds to let the control thread come alive again - on a Pentium Dual core @ 3GHz.
Without the usleep(usecs); function call, the cycle time is about 6 microseconds - so the system is - in principle - fast enough.
The same occurs with msleep(usecs=1); - the system goes up to 7.9 milliseconds immediately with this call.

In the main task i have the run started:
motor_thread.start(QThread::TimeCriticalPriority);

and in the motor task:
unsigned long usecs = 1;
usleep(usecs);

My problem is, that both functions seem to sleep much longer than the time specified.

There is only the IDE active on windows XP which runs the GUI and this control thread.
I am using QT Creator with QT 4.4.3 and the MinGW compiler.

Does anybody have experience with tightly timecontrolled processes?
Best regards

wysota
26th July 2009, 17:04
Unless you are running a real-time operating system (which you are not), you won't be able to control time precisely. You just have to live with that (or get a RT OS).