Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following snippet of code for that uses threads to multiply both halves of an array. Are the two threads using separate memory allocation

Consider the following snippet of code for that uses threads to multiply both halves of an
array. Are the two threads using separate memory allocation for their data?
#include
#include
int data[]={1,2,3,4,5,6,7,8};
void* runner(void* param){
int val -(int)param;
for(int i= val; i < val +4, i++)
data[i]*=2;
pthread_exit(0);
}
int main(int argc, char* argv[]){
pthread_t tids[2];
for(int i=0;i <2; i++)
pthread_create(&tids[i], NULL, runner, (void*)(i*4));
For(int i=0; i<2; i++)
pthread_join(tids[i], NULL);
}
Yes-each thread receives an different starting index in the data array
No -a separate memory allocation would require using a fork.
No-both threads are accessing the same piece of global data
Yes -we allocate memory for two different tids

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

Step: 3

blur-text-image

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

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions

Question

Derive expressions for the rates of forward and reverse reactions?

Answered: 1 week ago

Question

Write an expression for half-life and explain it with a diagram.

Answered: 1 week ago

Question

What do you mean by underwriting of shares ?

Answered: 1 week ago

Question

Define "Rights Issue".

Answered: 1 week ago