NOTE: PROGRAMMING C PROBLEM this part is from assignment #2 and question #2 Firs
ID: 3875172 • Letter: N
Question
NOTE: PROGRAMMING C PROBLEM
this part is from assignment #2 and question #2
First assignment Question number 1 and above one is question number 2:
1. Let's expand our model to now actually use threads for each CPU! Using pthreads, modify your program from Assignment #2, Question #2 to create one pthread per cpu that you s then sleep()1 for the duration of the task. Be careful to protect your shared data by using locks to control access! pecify. Each thread Look up "man sleep" to get a description of the sleep function.Explanation / Answer
/* C Program to swap two numbers using pointers and function. */
#include <stdio.h>
void swap(int *n1, int *n2);
int main()
{
int num1 = 5, num2 = 10;
// address of num1 and num2 is passed to the swap function
swap( &num1, &num2);
printf("Number1 = %d ", num1);
printf("Number2 = %d", num2);
return 0;
}
void swap(int * n1, int * n2)
{
// pointer n1 and n2 points to the address of num1 and num2 respectively
int temp;
temp = *n1;
*n1 = *n2;
*n2 = temp;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.