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 9074527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:39:20+00:00 2026-06-16T18:39:20+00:00

I’m writing a game in Android/OpenGL and am attempting to separate my OpenGL (render)

  • 0

I’m writing a game in Android/OpenGL and am attempting to separate my OpenGL (render) logic from my game update logic, by running each on its own thread in order to improve performance.

I managed to get each running on its own thread, however according to the Tracer in the DDMS, the threads are still running sequentially (world is my game update thread):

See url as I don’t have image privileges:
http://img849.imageshack.us/img849/9688/capturegff.png

The threads don’t seem to execute code at the same time.
I initialise the world thread as follows:

public class World implements Runnable {

    Thread thread;

    public World(...) {
    ...
        // Initialise the player/ball objects
        initialiseObjects();

        thread = new Thread(this, "World");
        thread.start();
}
}

I’ve implemented my own synchronisation between the two threads. Using an approach similar to that in Replica Island, I have two render buffers: the update thread (should ideally) write to the one of the buffers while the render thread is reading the other buffer. The buffer contains the information needed for the renderer to draw each sprite. Once the update thread has finished updating its buffer and the renderer has finished drawing, they swap buffers and the process repeats.

In code from the game update thread (similar code in the render thread):

    currBuffer.write();
    player.draw(currBuffer.getNext());

   ball.draw(currBuffer.getNext());

    if (particleEffect != null) {
        particleEffect.draw(currBuffer);
    }

    currBuffer.finished();

    while(otherBuffer.isFinished() == false) {
        //otherBuffer is finished once the render thread has finished drawing
    }

    DrawBuffer tempBuffer = currBuffer;
    currBuffer = otherBuffer;
    otherBuffer = tempBuffer;

    currBuffer.changed();
    while(otherBuffer.isChanged() == false) {
        //otherBuffer is changed once the render thread has also swapped buffered
    }

I can’t see how the above code could lead to the sequential execution of threads, though I’ve never attempted multi-threading before so it’s possible I’m doing something fundamentally wrong. My attempt to speed up the game have made it noticably slower and far less smooth. Any idea why the threads aren’t running in parallel?

UPDATE:
The issue was my phone’s processor was only single core. I was sure the Incredible S was dual core but alas it’s only single. I tried it on the S2 and it indeed ran the threads in parallel.

However, what then is the advantage of multi-threading if only the newer phones on the market support it? I don’t understand how Replica Island managed better performance on older, single core phones by implementing multi-threading. Surely the added overhead in synchronising between threads should lead to slower performance if there isn’t a second core to take advantage of?

The multi-threading led to slower performance on the single core due to having to generate the buffer that’s then passed to the draw thread. On the dual core, it was 5-10% faster, though at about 500 sprites the update cycle took longer than the draw cycle again due to the buffer, thus limiting the speed gains. Obviously with optimisation I can improve that but the question becomes whether it’s worth supporting multi-threading at the expense of single core processors. Is it possible to determine a phone’s processors in order to determine whether to use multi-threading or not at runtime?

  • 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-16T18:39:22+00:00Added an answer on June 16, 2026 at 6:39 pm

    Well, technically, 1 CPU runs only one code segment at a time. Your OS scheduler changes processes/threads in a fraction of milliseconds which gives you the illusion of running multiple processes at the same time.

    A way to notify runtime that your thread is done for now is calling Thread.yield. There is a busy loop in your code which does not help your situation. It keeps the CPU busy w/o doing anything.

    while(otherBuffer.isFinished() == false)
    

    you should use Loks instead of busy loop or you can try calling Thread.yield inside that while loop for an initial performance boost. Btw, also take a look at semaphore which is the simplest solution for such producer-consumer problems. If you want to keep your current codebase, you can use a lock per buffer.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

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.