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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:27:54+00:00 2026-05-18T00:27:54+00:00

I am writing a pthread program now. From what I experienced in C#, I

  • 0

I am writing a pthread program now. From what I experienced in C#, I think there might be a race condition in the creation of a thread.

for (i = 0; i < 10; i++)
{
    pthread_create(threads[i], NULL, &do_something, (void*)&data[i]);
}

Is it possible that local variable i is updated before the new thread is created? Therefore wrong data or threads entry in the arrays may be passed to the do_something function? At least in C# if I use Task.Factory.StartNew(), this is a big problem.

Thanks in advance.

  • 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-18T00:27:55+00:00Added an answer on May 18, 2026 at 12:27 am

    Once pthread_create returns everything that is passed by value will have been copied successfully, in fact the use of i is all evaluated prior to even entering the pthread_create function at all. The pointer itself is passed by value here too for the void* argument.

    The potential to create a race condition exists for example if you were passing i itself by reference (or pointer) and using that to access an array inside the start routine. This is not the case in this example though.

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

Sidebar

Related Questions

I'm writing a program with a consumer thread and a producer thread, now it
I'm trying to write a simple thread pool program in pthread. However, it seems
I am writing a program using threads in c++ in linux. Currently, I am
I am writing a program which has 8 threads. I am implementing a barrier
I'm writing a prime sieve program using eratosthenes' for class. I have 8 threads
The program is to create several threads where each thread increments a shared variable
I wrote a program in C++ under Linux. For thread I am using pthread.
I'm writing a program with threads for my Operating Systems class. It must compute
I'm writing a simple program to call a Java function from my C program.
Writing a python program, and I came up with this error while using the

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.