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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:48:45+00:00 2026-05-28T18:48:45+00:00

I have an application where pthread_join is being the bottleneck. I need help to

  • 0

I have an application where pthread_join is being the bottleneck. I need help to resolve this problem.

void *calc_corr(void *t) {
         begin = clock();
         // do work
         end = clock();
         duration = (double) (1000*((double)end - (double)begin)/CLOCKS_PER_SEC);
         cout << "Time is "<<duration<<"\t"<<h<<endl;
         pthread_exit(NULL);
}

int main() {
         start_t = clock();

         for (ii=0; ii<16; ii++) 
            pthread_create(&threads.p[ii], NULL, &calc_corr, (void *)ii);

         for (i=0; i<16; i++) 
            pthread_join(threads.p[15-i], NULL);

         stop_t = clock();

         duration2 = (double) (1000*((double)stop_t - (double)start_t)/CLOCKS_PER_SEC);
         cout << "\n Time is "<<duration2<<"\t"<<endl;

         return 0;
}

The time printed in the thread function is in the range of 40ms – 60ms where as the time printed in the main function is in the 650ms – 670ms. The irony is, my serial code runs in 650ms – 670ms time. what can I do to reduce the time taken by pthread_join?

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-28T18:48:46+00:00Added an answer on May 28, 2026 at 6:48 pm

    On Linux, clock() measures the combined CPU time. It does not measure the wall time.

    This is explains why you get ~640 ms = 16 * 40ms. (as pointed out in the comments)

    To measure wall time, you should be using something like:

    • gettimeofday()
    • clock_gettime()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application creates a helper pthread that I need to have run at a
For a c++ arm application I need to trace the memory allocations. To this
I have application which needs to use a dll (also written by me) which
I have application that makes different queries with different results so the caching in
I have Application settings stored under HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany branch. Settings must be same for different
I have Application written with GWT 1.7. I have one page where I upload
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I have Application X (not mine!) with Subform x1, x2, x3. How can I
I have Application X with Subform x1, x2, x3. The Subform has, because its

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.