Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; int arr[5]; void *incr(int n) { // Complete the code here } int main() { pthread_t t1, t2;int

#include #include #include pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; int arr[5];

void *incr(int n) { // Complete the code here }

int main() {

pthread_t t1, t2;int i; for(i=0;i<5;i++) {

arr[i]=1;

} pthread_create(); //Complete thread creation to pass the value to be incremented in thread 1 pthread_create(); //Complete thread creation to pass the value to be incremented in thread 2 pthread_join(t1,NULL); pthread_join(t2,NULL); exit(0); }

  • Write a program with one thread function, define an array with 5 elements as a global variable [ use the file mutex2.c for this lab].

  • Call the thread 2 times
  • First for incrementing the array elements by 2.
  • Second for incrementing the array elements by 3.
  • Give a "sleep(2)" in the for loop of the thread function to model some process happening in between.
  • Check if you are getting an expected output of incremented array elements.

  • Write a program with one thread function, define an array with 5 elements as a global variable [ use the file mutex2.c for this lab].

  • Call the thread 2 times
  • First for incrementing the array elements by 2.
  • Second for incrementing the array elements by 3.
  • Give a "sleep(2)" in the for loop of the thread function to model some process happening in between.
  • Check if you are getting an expected output of incremented array elements.

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_2

Step: 3

blur-text-image_3

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions