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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:15:15+00:00 2026-06-14T20:15:15+00:00

Let me show you the function first: for (i=0; i<3;i=i+2){ pthread_create(&thread1, NULL, &randtrack, (void

  • 0

Let me show you the function first:

for (i=0; i<3;i=i+2){
 pthread_create(&thread1, NULL, &randtrack, (void *)&rnum_array[i]);
 pthread_create(&thread2, NULL, &randtrack, (void *)&rnum_array[i+1]);
 pthread_join(thread1, NULL);
 pthread_join(thread2, NULL);
} 

print final result here;

My understanding is after two threads are created, the parent thread will blocked at join(thread1), what is the thread 2 actually come back earlier than thread1? How can make longer thread always stay behind?

Thanks

  • 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-14T20:15:16+00:00Added an answer on June 14, 2026 at 8:15 pm

    If thread2 finishes and thread1 hasn’t, you’ll continue waiting until thread1 finishes. Then you’ll wait until thread2 finishes, which will complete more or less instantaneously. The order in which you wait for the threads won’t matter (unless the threads try to interact with each other directly, such as by calling pthread_kill or pthread_join on each other).

    Update: Your design is completely wrong for what you’re actually trying to do. You want to do this:

    1. Create a structure to track the work that needs to be done. It should be protected by a mutex, track how many threads are currently working, and what the next work unit that needs to be assigned is.

    2. When you create the threads, have them rung a function that acquires the mutex, grabes the next unit of work, increments the number of threads running, and then does the work.

    3. When a thread completes a work unit, it should acquire the mutex, decrement the number of threads running, and see if there’s more work to do. When there’s no work to do, the thread should terminate.

    4. You can now wait for all threads to terminate, which will only happen when all the work is done. This eliminates the loop over the work units.

    And please learn a very important general rule — threads are just the things that get work done. What you want your code to focus on is doing the work, not how it will be done. Try to wait for work to be done, not for threads to be done.

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

Sidebar

Related Questions

Let me show the code first. WCF servicecontract function: public List<VenueData> GetVenues() { List<VenueData>
Let me show what I need first so you can understand my problem. I
I have a few weird issues I need to solve. First, let me show
I have a list of elemnts (let's say 10) and I only show first
private function openAllNodes(event:TimerEvent):void { //Alert.show(event.target.currentCount); var index:int =event.target.currentCount - 1; myTree.openItems = treeData..node[index] ;
Let me share my jQuery part first $(.btnUpdateInput).click(function() { //alert(Update); var BldDocumentId = $(#BldDocId).val();
I am having a difficult time sorting through this PHP/MySQL issue. Let me show
a funny problem ... i can't understand it.. let me show you what i
I want to let a div show and disappaer with jquery and css. The
Specifically how can I: Show a button which will let the user browse through

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.