question on file, write code in visual c++

1 answer below »
Answered Same DayOct 11, 2021

Answer To: question on file, write code in visual c++

Arun Shankar answered on Oct 23 2021
136 Votes
Final and complete answer/program_without_semaphores.cpp
#include
#include

using namespace std;
// Global array
int arr[6000];
// Global variable sum
int sum = 0;
int section = 0;
// The function to compute sum
void* compute_sum(void* arg)
{
// Each thread computes sum of 1/4th of array
int mysection = section++;
for (int i=mysection*1500; i<(mysection+1)*1500;i++)
sum += arr[i];
return arr;
}
int main()
{
// Initialize the global array
for(int i=0;i<6000;i++)
arr[i] = i;

// Declare the four threads
pthread_t threads[4];
// Creating 4 threads
for(int i=0;i<4; i++)...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here