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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:23:47+00:00 2026-05-23T17:23:47+00:00

I’m approaching C programming with threads and I can’t get this program to work

  • 0

I’m approaching C programming with threads and I can’t get this program to work properly. Basically there’s a vector with k elements, n threads and each thread has to calculate the max on its k/n elements.

My code is (please note it’s not the whole code):

// Struct code used later
struct maxStruct 
{
    double *vettore;
    int dimensione;
};

// Gathering data input from user 

[ . . . ]
vector = (double *) malloc (dimensione * sizeof(double));
pid_thread = (int *) malloc (numero_thread * sizeof(int));
thread = (pthread_t *) malloc (numero_thread * sizeof(pthread_t));

// Generating the vector

[ . . . ]
for (i = 0; i < numero_thread; i++)
    {
        e = generaStruct(i, vettore, dimensione, numero_thread);
        if (status = pthread_create(&thread[i], NULL, calcolaMassimo, (void *) e))
                {
                    pthread_perror("pthread_join", status);
                    exit(1);
                }
    }

//Note that the function doesn't calculate the max, I've coded it in this way
//in order to see whether it was being called by each thread and apparently it is not.
void *calcolaMassimo(void * e)
{
    printf("Sono chiamata!!\n");
    struct maxStruct *sottoVettore = e;

    printf("Dimensione: %d\n", ((*sottoVettore).dimensione));

}

Apparently this function is not being called by each thread and I can’t figure out why. Will you please help me solve this issue?

  • 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-23T17:23:48+00:00Added an answer on May 23, 2026 at 5:23 pm

    Firstly, a minor nit pick, the idiomatic way to write (*sottoVettore).dimensione) is sottoVettore->dimensione.

    The process containing all of threads will exit when main() exits. I know you said you’re joining in you’re actual code so that should not be an issue but if you’re not joining in the test code then that could be an issue.

    It is also possible that the issue is not that the code in each thread isn’t executing, but that the statements aren’t actually reaching stdout. You might want to try a fflush(stdout) at the end of calcolaMassimo and see if that changes things.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.