CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2014
    Posts
    1

    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
    naruto90

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: cyclic thread with speicifc time interval

    You might find this of interest re waitable timers
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    together with its links.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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
  •  





Click Here to Expand Forum to Full Width

Featured