Question: I have this code but it is not running or printing correctly. Please fix this code for me and post it here. the output that

I have this code but it is not running or printing correctly. Please fix this code for me and post it here.

the output that I am getting is:

Begin Multi-threading

RUN FINISHED; Segmentation fault: 11; real time: 0ms; user: 0ms; system: 0ms

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

/* * File: main.c * * * Created on April 1, 2018, 5:00 PM */

#include #include

#include

// Using one global variable

int var = 0;

// This function is called whenever a new thread starts execution

void *runThread(void *vargp)

{

int *myid = (int *)vargp;

// Using one local variable along with global variable

static int varLocal = 0;

// Print the argument, static and global variables

printf("Thread ID: %d, Value of local variable: %d, Value of global variable: %d ", *myid, ++varLocal, ++var);

++varLocal;

++var;

}

int main(int argc, char** argv) { int i;

pthread_t tid;

printf("Begin Multi-threading ");

pthread_create(&tid, NULL, runThread, (void *)1);

pthread_create(&tid, NULL, runThread, (void *)2);

pthread_create(&tid, NULL, runThread, (void *)3);

pthread_create(&tid, NULL, runThread, (void *)4);

pthread_join(tid, NULL);

printf("All threads are done! ");

pthread_exit(NULL);

return 0;

return (EXIT_SUCCESS); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!