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 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
When writing multithreaded applications, one of the most common problems experienced is race conditions.
When writing a switch statement, there appears to be two limitations on what you
When writing multi-threaded applications, one of the most common problems experienced are deadlocks. My
I am writing a server program in C wherein every time a client connects,
I'm actually writing an MPI program. This is a basic client / server pattern.
I have a pthread waiting on a condition variable using pthread_cond_wait() . It's waiting
Writing my first JQTouch app. When I go from #login to #home , a
I am writing a program with a few critical sections. The thing is I
I'm sure I'm missing something basic, but I'm writing a program that fork()s several

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.