Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

copy of the program n4 24 PMis skeleton.cpp, which is C also in the same directo

ID: 3749274 • Letter: C

Question

copy of the program n4 24 PMis skeleton.cpp, which is C also in the same directory, and name it pthreads pl.cpp Note the use of the pthread create function in main). Read the Linux manual page that describes the pthread create function [URL pthread create] and make sure that you understand the functionality that pthread create provides and how to call (inwoke) this function. Modify the program to declare and initialize a global array named my messages to the messages below English:Hello!" French: Bonjour! Spanish: Hola! comment that says TODO: Modity according to assignment requirements" and the if (ro) check). So, each thread will essentially execute the same function, but will print a different message based orn the parameter it recelves. 6. Compile your program and run it several times. Note that the output of your program is likely to look garbled and may not always show the greetings in the same order. Run the program multiple times until you are confident that all of the threads are executing. Expected Output: Your program should produce the following output, but possibly with a Englishi Hette erman: Guten Tag different order of greetings: Main Code nclude·pthread.h- using namespace sad This fanction shows the skelcton that pehrcad functions must adhere to Copy this skeleton for any pthread function you need so define, In the copy, modify the name of hc function and the function body as needed void routincNama void "arg TODO: Add code that implements W the threads functionality cout

Explanation / Answer

#include<pthread.h>
#include<iostream>
#include<unistd.h>
using namespace std;

//decalre global variable my_messages
char my_messages[4][20]= { "English: Hello!","French: Benjour!","Spanish: Hola!","Germal: Guten Tag!"};

void *runtimename(void *vargp)
{
// Store the value argument passed to this thread
int *myid = (int *)vargp;
  
// index to access messages
static int s = 0;
  
// print hello in different languages
cout<<"Thread is running, messge: "<< my_messages[s++]<<endl;
}
  
int main()
{
int i;
pthread_t tid[4];
  
// create four threads to display different messages.
for (i = 0; i < 4; i++)
pthread_create(&tid[i], NULL, runtimename, (void *)&i);
  
pthread_exit(NULL);
return 0;
}

-------------------------------------------
//output
Thread is running, messge: English: Hello!   
Thread is running, messge: French: Benjour!
Thread is running, messge: Spanish: Hola!
Thread is running, messge: Germal: Guten Tag!