Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Coding exercise ( Language: C ) You tutor students part - time as part of your work - study program. Currently, the students are facing
Coding exercise Language: C
You tutor students parttime as part of your workstudy program. Currently, the students are facing threads and memory management for the first time and theyre having a hard time. To help them, you devised an exercise for them to practice with. One of the students submitted the following code, everything they added is encased to the base code supplied with Students Code Comment.
#include
#include
#include
int threads;
double sol;
struct matrix int data; int size; int size; ;
void runnervoid param
Students Code
struct matrix matrices struct matrixparam;
int startrow intparam;
int endrow startrow ;
for int i startrow; i endrow; i
for int j ; j matricessize; j
solij;
for int k ; k matricessize; k
solij matricesdataik matricesdatakj;
Students Code
pthreadexit;
void matrixOperationint scalar, struct matrix X struct matrix Y
Students Code
pthreadt tidthreads;
int rowsperthread Xsize threads;
int remainingrows Xsize threads;
int threadargsthreads;
int startrow ;
for int i ; i threads; i
threadargsi startrow;
int rows rowsperthread remainingrows : ;
remainingrows;
startrow rows;
pthreadcreate&tidi NULL, runner, &threadargsi;
for int i ; i threads; i
pthreadjointidi NULL;
Students Code
Prints out the solution matrix
printfResult
;
forint i ; i Xsize; i
printf;
forint j ; j Xsize; j
j Xsize printff solij : printff solij;
i Xsize printf : printf
;
printf
;
return;
Students Code
int main
struct matrix X Y;
Xdata;
Xdata;
Xdata;
Xdata;
Xsize;
Xsize;
Ydata;
Ydata;
Ydata;
Ydata;
Ysize;
Ysize;
threads ;
matrixOperation X Y;
threads ;
Ydata;
matrixOperation X Y;
Ysize;
threads ;
matrixOperation X Y;
return ;
Students Code
Students Result:
Result
Result
Result
Expected Result:
Result
Result
ILLEGAL OPERATION
There are multiple errors within the code, how would you go about resolving those issues and explaining the changes made such that the student can improve? Was the approach efficient? Only use pThreads
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