Question: Text File to explain the code and please Add screenshoot as Well The Code is Given Below Use an IDE (Visual Studio, or editor in
Text File to explain the code and please Add screenshoot as Well
The Code is Given Below
Use an IDE (Visual Studio, or editor in the Ubuntu virtual machine, or editor in school cluster mamba.urc.uncc.edu).
Compile the c code: gcc -g -Wall -o c_pthread_hello c_pthread_hello.c -lpthread
Run the code: ./c_pthread_hello 3. After copy and save the file.
Explain in text file about the compiling command and execution command.
Execute the code for five times.
What do you observe?
Adapt the code to mimic your team. Main thread displays the class title; each thread displays the team member name (it is okay to hard coding title and member name in the subquestion)
Code
/* * c_pthread_hello.c */
#include
int thread_count;
void * hello(void * rank);
int main(int argc, char* argv[]){ long thread; pthread_t* thread_handlers;
thread_count = strtol(argv[1], NULL, 10); thread_handlers = malloc(thread_count * sizeof(pthread_t));
printf("Create pthread_t data structure"); for (thread = 0; thread < thread_count; thread++){ pthread_create(&thread_handlers[thread], NULL, hello, (void *) thread); }
printf("Hello from main thread ");
for (thread = 0; thread < thread_count; thread++){ pthread_join(thread_handlers[thread], NULL); }
free(thread_handlers); thread_handlers = NULL;
return 0; }
void* hello(void* rank){ long my_rank = (long)rank;
printf("Hello from thread %ld of %d ", my_rank, thread_count);
return NULL; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
