Answered step by step
Verified Expert Solution
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;
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started