Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 938577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:40:01+00:00 2026-05-15T21:40:01+00:00

Ive got an application where I want to display a frame every x milliseconds.

  • 0

Ive got an application where I want to display a frame every x milliseconds.

Previously I did it like this:

class SomeClass
{
    boost::thread thread_;
    boost::timer timer_;
public:
    SomeClass() : thread_([=]{Display();}) 
    {
    }

    void Display
    {    
        double wait = 1.0/fps*1000.0;    
        while(isRunning_)
        {
             double elapsed = timer.elapsed()*1000.0;
             if(elapsed < wait) 
                  boost::this_thread::sleep(boost::posix_time::milliseconds(static_cast<unsigned int>(wait - elapsed)));
             timer.restart();

             // ... Get Frame. This can block while no frames are being rendered.

             // ... Display Frame.
      }
    }
}

However I dont think solution has very good accuracy. I might be wrong?

I was hoping to used boost::asio::deadline_timer instead, but I’m unsure how to use it.

This is what ive tried, which doesn’t seem to wait at all. It seems to just render the frames as fast as it can.

class SomeClass
    {
        boost::thread thread_;
        boost::asio::io_service io_;
        boost::asio::deadline_timer timer_;

    public:
        SomeClass() : timer_(io_, 1.0/fps*1000.0)
        {
            timer_.async_wait([=]{Display();});
            thread_ = boost::thread([=]{io_.run();})
        }

        void Display
        {    
                double wait = 1.0/fps*1000.0;    
                while(isRunning_)
                {
                    timer_.expires_from_now(boost::posix_time::milliseconds(wait_)); // Could this overflow?

                    // ... Get Frame. This can block while no frames are being rendered.

                    // ... Display Frame.

                     timer_.async_wait([=]{Display();});
                }
        }
    }

What am I doing wrong? And if I got this solution working would it be better than the first?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:40:02+00:00Added an answer on May 15, 2026 at 9:40 pm

    Remember that the accuracy with which a frame is displayed is limited by the refresh rate of your display (typically 17 ms for a 60 Hz display, or 13 ms for a 75 Hz display). If you’re not syncing to the display refresh then you have an indeterminate latency of 0 – 17 ms to add to whatever timing method you use, hence accuracy doesn’t really need be much better than 10 ms (even 1 ms is probably overkill).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've got an application whose window behavior I would like to behave more
I have a simple quiz application and I want display a nice timer /
I've got images as IplImage that I want to display in a small Gtkmm
I've got a view when I want to use UIPickerView but my application supports
I need something like the C function getservbyname() for a Java application. I've got
I've got two applications I'm developing using Qt on windows. I want the user
I've got an application that is very graphics intensive and built on DirectX and
I've got an application that's using string.compare(string,string) to sort some values. The thing I
I've got an application that just shipped. Since I wrote it, I've learned about
I've got an application that uses DirectShow/DirectSound which plays videos and extracts the video/sound.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.