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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:25:10+00:00 2026-05-25T01:25:10+00:00

I have in my program a loop that will fill an 3D cube with

  • 0

I have in my program a loop that will fill an 3D cube with pixels (GL_POINTS), so to speed up things a little I thought i could use OpenMP and separate this for loop in my multi-core processor.

The problem is that any time I use OpenMP in the loop the program segfaults, here is the code of the loop:

glBegin(GL_POINTS);
#pragma omp parallel for
for (int a = 0; a < m_width * m_height; a++)
{
    uint8_t r, g, b;
    r = m_data[a * m_channels];
    g = m_data[a * m_channels + 1];
    b = m_data[a * m_channels + 2];

    glColor3ub(r, g, b);
    glVertex3f(r / 255.0 - 0.5, g / 255.0 - 0.5, b / 255.0 - 0.5);
}
glEnd();

As you can see, the code just get some information from m_data array and then call glColor3ub and glVertex3f with it, if I run this code without the #pragma the code runs great.

The gdb shows me that the program segfaults when it reach the glColor3ub, making clear that the problem is something with openGL, maybe the function is not thread-safe? Can I make something to correct the code?

  • 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-25T01:25:10+00:00Added an answer on May 25, 2026 at 1:25 am

    Don’t mess with a single OpenGL context and multithreading, or guard every use of OpenGL by a critical section (which won’t buy you anything performance-wise). What you can probably do is use vertex arrays/buffers (which will be faster anyway) and fill their data using multiple threads before drawing it in a single thread.

    What should happen if one thread sets the current color and gets unscheduled before it draws the vertex? But what definitely will happen is that the driver gets interrupted in the middle of some operation and its internal data gets totally messed up.

    OpenGL is definitely not thread safe.

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

Sidebar

Related Questions

I have a program in Octave that has a loop - running a function
So I have a Linux program that runs in a while(true) loop, which waits
I have a program that needs to use sleep. Like really needs to. In
I have a program that's resident in flash and will run from flash. Early
I have a program that will analyzes source code. It can recursively go through
I have writted a Java program that will be able to add customers to
I have python code below that will loop through a table and print out
For class I have an assignment: Write a C++ program that will output the
I have a string with possible command line arguments (using an Read-Eval-Print-Loop program) and
I have a following code in a most inner loop of my program struct

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.