Please complete Part 1. The code is also below:

#include <pthread.h>
#include <iostream>
using namespace std;
void *PrintHello(void *arg)
{
int actual_arg = *((int*) arg);
cout << "Hello World from thread with arg: " <<
actual_arg << "!\n";
return 0;
}
int main()
{
pthread_t id;
int rc;
cout << "In main: creating thread \n";
int t = 23;
rc = pthread_create(&id, NULL, PrintHello, (void*) &t);
if (rc){
cout << "ERROR; return code from pthread_create() is "
<< rc << std::endl;
return -1;
}
pthread_exit(0);
}
|
//Program code #include <pthread.h> using namespace std; void *PrintHello(void *arg) int main() cout << "Enter a number ";
if (rc){ pthread_exit(0); |
|
//Sample output In main: creating thread Enter a number 52 Hello World from thread with arg: 52! |
|
Screen shot output
|
Screen Shot of the program

Please complete Part 1. The code is also below: #include <pthread.h> #include <iostream> using namespace std;...
i want to fix the solution and provide an explanation why the pthread_join is not working as intended? #include <stdio.h> /* standard I/O routines */ #include <pthread.h> /* pthread functions and data structures */ void* PrintHello(void* data) { pthread_t tid = (pthread_t)data; /* data received by thread */ pthread_join(tid, NULL); /* wait for thread tid */ printf("Hello from new thread %u - got %u\n", pthread_self(), data); pthread_exit(NULL); /* terminate the thread */ } /* like any C program, program's execution...
Please finish the following program /** * Basic POSIX Thread (pthread) Usage 1. * * By walking through this example you’ll learn: * - How to use pthread_create(). * - How to use pthread_exit(). * - How to use pthread_join(). * */ #include <stdio.h> #include <unistd.h> #include <pthread.h> #include <sys/wait.h> void* ninja(void* arg){ printf("Who’s there?"); fflush(stdout); pthread_exit("ninja"); } // // Expected output: // // Knock knock. // Who's there? - from ninja // Knuc...kles. // int main(int argc, char* argv[]){...
MOdify the program below to do 3x3 matrix mutiplications: #include <iostream> #include <cstdlib> #include <pthread.h> using namespace std; int A[3] [3] = {{1,2},{3,4}}; int B[3] [3] = {{5,6},{7,8}}; int C[3] [3]; struct Position{ int row; int col; }; void *CalculateElement(void *pos){ Position *p = (Position *)pos; C[p->row][p->col] = 0; for(int i = 0; i < 3; i++){ C[p->row][p->col] += A[p->row][i]*B[i][p->col]; } pthread_exit(NULL); } const int NUM_THREADS = 4; int main() { ...
1. (50 pts) Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string ('A'<>'Z', 'B'<->'Y', 'C''X', etc). You should divide this conversion task among the n threads as evenly as possible, Print out the...
Read the following code, threaded recursive calculation of Fibonacci number of n: #include <stdio.h> #include <stdlib.h> #include <pthread.h> void *fib(void *arg); int main(int argc, char **argv){ int n = atoi(argv[1]); printf("%d\n", (int)fib(n)); } void *fib(void *arg){ int n; pthread_t thread1; pthread_t thread2; void *a; void *b; int c; n = (int)arg; if (n <= 0) return 0; if (n == 1) return 1; pthread_create(&thread1, NULL, fib, n-1); ...
Here is the code from the previous three steps:
#include <iostream>
using namespace std;
class Student
{
private:
//class variables
int ID;
string firstName,lastName;
public:
Student(int ID,string firstName,string lastName)
//constructor
{
this->ID=ID;
this->firstName=firstName;
this->lastName=lastName;
}
int getID() //getter method
{
return ID;
}
virtual string getType() = 0; //pure virtual function
virtual void printInfo() //virtual function to print basic details
of a student
{
cout << "Student type: " << getType() <<
endl;
cout << "Student ID: " << ID...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
Pleas help I need to create and array to add to my code
something like this
for (i = 0; i < NUM_THREADS; ++i) {
thr_data[i].tid = i;
if ((rc = pthread_create(&thr[i], NULL, thr_func,
&thr_data[i]))) {
fprintf(stderr, "error: pthread_create, rc: %d\n", rc);
return EXIT_FAILURE;
::::::::: CODE :::::::::::::
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
int sharedVar = 0;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
/* thread handler */
void *threadHandler(void *vargp)
{
int i = 0;
pthread_mutex_lock(&mutex);
...
What is printed by the following program? (read the code carefully) #include <iostream> using namespace std; class A { public: int x; }; int main() { A *a = new A; A *b = new A; a->x=1; b->x=1; if (a == b) { cout << "black"; } else { cout << "white"; } delete a; delete b; return 0; }
Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }