CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Timer

  1. #1
    Join Date
    Jun 2004
    Location
    Brazil - São Paulo
    Posts
    62

    Question Timer

    Hello,

    I have an EXE COM object that has a worker thread. This object must schedule some actions and for that it uses another thread and a WaitableTimer object. The problem I am facing is the following:

    1º) When the worker thread is not created, the "timer" thread works just fine, with the intervals being respected correctly (with acceptable error margins);
    2º) When the worker thread is created and is performing its job, the "timer" thread does not respect small intervals anymore (values below 250ms).

    I have tried to use SetThreadPriority() and SetPriorityClass() APIs (TIME CRITICAL and REALTIME), but the results were exactly the same... My opinion is: scheduling of threads inside the process is interfering in my "timer" thread.

    Does anyone know how to solve this? I can use other ideas for timing issues, but they must be precise ones.

    Thanks in advance,
    Wagner

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Timer

    What kinds of intervals are you talking about here? Windows is not a realtime OS, so you are not going to be able to get really precise times while some thread is working.

    Viggy

  3. #3
    Join Date
    Jun 2004
    Location
    Brazil - São Paulo
    Posts
    62

    Re: Timer

    Hello,

    I will need 10ms intervals... The problem is the following:

    1º) When there is only the "timer" thread working, I got 14~15ms intervals (that is acceptable);

    2º) When I start another thread (working thread), this value goes up to 124ms.

    This 124ms interval seems to be fixed for intervals < 150ms, that is why I think it is a problem of thread scheduling.

    Thanks,
    Wagner

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Timer

    Right. It's also a consequence of using a non-realtime os. I don't think it's possible for you to get the resolution that you want. 10ms is short. Very short. Check out this discussion of quantums:

    http://www.codeguru.com/forum/showth...hlight=quantum

    You can't completely control the OS in terms of what threads get run, and at what times. Even when you set your thread to "realtime" priority, other threads will get some (little) CPU time. When that happens, all your time critical code goes to pot.

    Viggy

  5. #5
    Join Date
    Jun 2004
    Location
    Brazil - São Paulo
    Posts
    62

    Re: Timer

    Thanks for the help... I will try to use something else! If I find, I will let you know!!!

    Thanks again,
    Wagner

  6. #6
    Join Date
    Dec 2003
    Location
    Montreal
    Posts
    58

    Re: Timer

    We have found that under WIndows NT/2000 you can get 50 ms most of the time, 20 ms generally but the computer needs to be properly setup. Under pure Windows you can expect delays > 1000 ms from time to time!

    You can look at the embedded Windows systems for better contol or try Venture COM's RTX for Windows, you can get sub ms level response.

    RTX runs your real-time code under Windows, it is hard real-time, but it allows you to mix Windows with hard real time.

    RTX Home page
    Last edited by CJ1; August 27th, 2004 at 01:54 PM.

  7. #7
    Join Date
    Jun 2004
    Location
    Brazil - São Paulo
    Posts
    62

    Re: Timer

    Thanks for the help... I have downloaded the evaluation RTX and I will try to use it!!!

    Thanks again,
    Wagner

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured