Question: 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;
void runnervoid param
int val intparam;
forint i val; i val i
datai;
pthreadexit;
int mainint argc, char argv
pthreadt tids;
forint i;i ; i
pthreadcreate&tidsi NULL, runner, voidi;
Forint i; i; i
pthreadjointidsi NULL;
Yeseach thread receives an different starting index in the data array
No a separate memory allocation would require using a fork.
Noboth 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
