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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:41:00+00:00 2026-06-13T04:41:00+00:00

I have an OpenGL app that needs to perform some computations in the background

  • 0

I have an OpenGL app that needs to perform some computations in the background before displaying data.

Sequentially, what I’m doing is :

  1. prepareData (calls background thread)
  2. _doLongComputation (in background thread, calls _transferToGPU)
  3. _transferToGPU (main thread)

Since I’m using synchronized blocks on the same object glData, critical sections shouldn’t be accessed by more than one thread at the same time, but unfortunately this isn’t the case, and I can’t figure out why.

Any ideas?

The important parts of the code are below :

@property (atomic, retain) NSData *glData;

...snip snip...

- (void) _doLongComputation {
  @synchronized (glData) {
    // Create a buffer (long operation, done in C++)
    unsigned long size;
    unsigned char* buffer = createBuffer(&size);

    // Create NSData to hold it safely
    self.glData = [NSData dataWithBytesNoCopy:buffer length:size freeWhenDone:YES];
  }

  // Don't wand to deal with locking the OpenGL context,
  // so we do all the OpenGL-related stuff in the main queue
  dispatch_async (dispatch_get_main_queue(), ^{
    [self _transferToGPU];
  });
}

- (void) _transferToGPU {
  @synchronized (glData) {
    ...snip snip...

    // Transfer buffer to GPU
    glBufferData(GL_ARRAY_BUFFER,
                 glData.length,
                 glData.bytes,
                 GL_STATIC_DRAW);

    // We're done, so set the buffer to nil
    self.glData = nil;
  }
}

- (void) prepareData {
  [self performSelectorInBackground:@selector(_doLongComputation)];
}
  • 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-13T04:41:01+00:00Added an answer on June 13, 2026 at 4:41 am

    I think you should synchronize on self instead.

    Synchronizing on a variable conceptually creates an implicit mutex using the address pointed to by that variable. If the variable points to a different object, it will be a different mutex, even if it’s still the same variable in your code. This means that setting glData in your @synchronized(glData) blocks defeats the purpose of your synchronization attempt.

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

Sidebar

Related Questions

I have a SWT app that opens a OpenGL window (using the LWJGL library)
I have a Opengl ES 1.x ANdroid 1.5 app that shows a Square with
Good afternoon. I have been making a small openGL based app for android that
I have a simple OpenGL app that displays arbitrary 3D models. I'd like to
I have a graphical app that needs to test the resolution of the display
I have an artsy opengl app that I am working on. The final product
I have an iPad app with UI written in OpenGL ES 2.0, some UI
I'm developing an image warping iOS app with OpenGL ES 2.0. I have a
I have an OpenGL application that outputs stereoscopic 3D video to off-the-shelf TVs via
I have learn OpenGL programming for some time.And I found a very strange phenomenon

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.