Results 1 to 2 of 2

Thread: QThread under Windows XP - usleep(), msleep() problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question QThread under Windows XP - usleep(), msleep() problem

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QThread under Windows XP - usleep(), msleep() problem

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Thread problem with windows
    By vratojr in forum Qt Programming
    Replies: 17
    Last Post: 16th June 2006, 08:34
  2. problem of porting from windows to linux
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2006, 08:42
  3. Replies: 10
    Last Post: 28th April 2006, 15:48
  4. Problem building Qt4.1.0 with thread support on windows XP
    By pavithra in forum Installation and Deployment
    Replies: 1
    Last Post: 1st April 2006, 11:35
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 08:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.