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

  • Home
  • SEARCH
  • 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 8933341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:30:53+00:00 2026-06-15T09:30:53+00:00

So I have a single-threaded game engine class, which has separate functions for input,

  • 0

So I have a single-threaded game engine class, which has separate functions for input, update and rendering, and I’ve just started learning to use the wonderful boost library (asio and thread components). And I was thinking of separating my update and render functions into separate threads (and perhaps separate the input and update functions from each other as well). Of course these functions will sometimes access the same locations in memory, so I decided to use boost/thread’s strand functionality to prevent them from executing at the same time.

Right now my main game loop looks like this:

void SDLEngine::Start()
{
    int update_time=0;
    quit=false;
    while(!quit)
    {
        update_time=SDL_GetTicks();
        DoInput();//get user input and alter data based on it
        DoUpdate();//update game data once per loop
        if(!minimized)
            DoRender();//render graphics to screen
        update_time=SDL_GetTicks()-update_time;
        SDL_Delay(max(0,target_time-update_time));//insert delay to run at desired FPS
    }
}

If I used separate threads it would look something like this:

void SDLEngine::Start()
{
    boost::asio::io_service io;
    boost::asio::strand strand_;
    boost::asio::deadline_timer input(io,boost::posix_time::milliseconds(16));
    boost::asio::deadline_timer update(io,boost::posix_time::milliseconds(16));
    boost::asio::deadline_timer render(io,boost::posix_time::milliseconds(16));
    //
    input.async_wait(strand_.wrap(boost::bind(&SDLEngine::DoInput,this)));
    update.async_wait(strand_.wrap(boost::bind(&SDLEngine::DoUpdate,this)));
    render.async_wait(strand_.wrap(boost::bind(&SDLEngine::DoRender,this)));
    //
    io.run();
}

So as you can see, before the loop went: Input->Update->Render->Delay->Repeat

Each one was run one after the other. If I used multithreading I would have to use strands so that updates and rendering wouldn’t be run at the same time. So, is it still worth it to use multithreading here? They would still basically be running one at a time in separate cores. I basically have no experience in multithreaded applications so any help is appreciated.

Oh, and another thing: I’m using OpenGL for rendering. Would multithreading like this affect the way OpenGL renders in any way?

  • 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-06-15T09:30:55+00:00Added an answer on June 15, 2026 at 9:30 am

    You are using same strand for all handlers, so there is no multithreading at all. Also, your deadline_timer is in scope of Start() and you do not pass it anywhere. In this case you will not able to restart it from the handler (note its not “interval” timer, its just a “one-call timer”).

    I see no point in this “revamp” since you are not getting any benefit from asio and/or threads at all in this example.

    These methods (input, update, render) are too big and they do many things, you cannot call them without blocking. Its hard to say precisely because i dont know whats the game and how it works, but I’d prefer to do following steps:

    • Try to revamp network i/o so its become fully async
    • Try to use all CPU cores

    About what you have tried: i think its possible if you search your code for actions that really can run in parallel right now. For example: if you calculate for each NPC something that is not depending on other characters you can io_service.post() each to make use all threads that running io_service.run() at the moment. So your program stay singlethreaded, but you can use, say, 7 other threads on some “big” operations

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

Sidebar

Related Questions

I have an old C++ library which has been designed for use in single-threaded
I have coded a single threaded client server model which does following: Server loops
I have a single-threaded linux app which I would like to make parallel. It
I have this service which is Singleton and Single threaded and serves bunch of
I have the following code which uses a single-threaded executor service, but running it
I have a single-threaded application that uses 3 SQLite databases in 3 different files
I have a single-threaded Rails app running on thin in single-threaded mode on Heroku
I'm at the end of my rope here: I have a single-threaded C++ program.
[Cross-posted from lib-curl mailing list] I have a single threaded app (MSVC C++ 2005)
i have a single filed which i need to clone with a clone button

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.