Question: 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
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
