cyclic thread with speicifc time interval
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: cyclic thread with speicifc time interval

  1. #1
    Join Date
    Apr 2014

    cyclic thread with speicifc time interval

    It's the first time that I use codeguruand I hope that I get my question answered here
    I have a robotcell with 4 robots in it. a A so called "update thread" (I hope you kow know what I mean) reads after a specific interval e.g. 1000 ms the coordinates of the roboters and puts them in a data structure.

    Finally we have a thread for each robot (so 4) threads (again each have different read interval times) which read the coordinates and calculate the trajectory. I have to use win32api functions.

    I have never done anything with time intervals in C++, so can anybody show me examples how to do that?
    i have a threadbase class (with start and stop functions) and a critical section class.
    but i need an idea how to "poll" the threads with an specific time interval.
    i've read something ith createwaitabletimer, but I'm not sure if I#m on the right way.

    Best regards

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: cyclic thread with speicifc time interval

    You might find this of interest re waitable timers
    together with its links.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. This post is public domain as specified at

    C, C++ Compiler: Microsoft VS2017

  3. #3
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: cyclic thread with speicifc time interval

    note that waitable timers are NOT precise. you'll get "more or less" the interval you wanted, but it can be less and can be substantially more.

    if you need things to be actually time coordinated, you'll need quite a bit more scaffolding work to get something like that going in Windows. Windows isn't an RTOS, and getting any kind of hard timing guarantees is tricky.

    why do you need 5 threads for this ? It seems entirely doable to do this on a single thread with either a regular WM_TIMER (if timing isn't critical) or on a multimedia timer if it's semi critical.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This a survey!

HTML5 Development Center