Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #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 *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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn Mysql The Easy Way A Beginner Friendly Guide

Authors: Kiet Huynh

1st Edition

B0CNY7143T, 979-8869761545

More Books

Students also viewed these Databases questions

Question

Describe the three causes of social loafing.

Answered: 1 week ago

Question

Describe how to train managers to coach employees. page 404

Answered: 1 week ago

Question

Discuss the steps in the development planning process. page 381

Answered: 1 week ago