Question
edit and write in c++ #include #include #include #define MAX_NUM_THREADS 8 char *messages[MAX_NUM_THREADS]; struct thread_data { int thread_id; char *message; }; struct thread_data thread_data_array[MAX_NUM_THREADS]; void
edit and write in c++
#include
char *messages[MAX_NUM_THREADS];
struct thread_data { int thread_id; char *message; };
struct thread_data thread_data_array[MAX_NUM_THREADS];
void *PrintHello(void *threadarg) { int taskid; char *hello_msg; struct thread_data *my_data;
sleep(1); my_data = (struct thread_data *) threadarg; taskid = my_data->thread_id; hello_msg = my_data->message; printf("Thread %d: %s ", taskid, hello_msg); pthread_exit(NULL); }
int main(int argc, char *argv[]) { pthread_t threads[MAX_NUM_THREADS]; int *taskids[MAX_NUM_THREADS]; int rc, t;
size_t malloc_size = 100;
for (int i = 0; i < 8; i++) { messages[i] = malloc(malloc_size * sizeof(char)); /* allocates 100 bytes */ printf("Enter messages:%d ",i+1); // as indicated in question input is taken from user scanf("%[^ ]%*c", messages[i]); // geting string until newline character is entered
//Then, with this %*c, it reads newline character and here used *indicates that this newline character is discarded } for(t=0;t
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started