Question: Consider the following function ( part of a larger program ) which applies a blur to an image. This filter is implemented using an averaging
Consider the following function part of a larger program which applies a blur to an image.
This filter is implemented using an averaging method ie like your homework Does this
code handle threads efficiently, or inefficiently? Explain.
Assume that the program compiles and produces the expected result
pthreadt tidsTHREADCOUNT;
Pixel input;
Pixel output;
pthreadmutext outputmutex;
OMITTED: main method that loads file, calls processimage, and saves the file.
int processimage
forint i; i THREADCOUNT; i
pthreadcreate&tidsi NULL, blur, i;
forint ; i THREADCOUNT; i
pthreadjoin&tidsi NULL;
void blurvoid arg
pthreadmutexlockoutputmutex;
all the filter code goes here and works on column
pthreadmutexunlockoutputmutex
pthreadexit;
Efficiently it creates threads, and uses different memory allocations for each of the threads
Efficiently it creates threads, gives them an opportunity to do computation in parallel, and then joins
all of them
Inefficiently the thread join happens after each thread create so only one thread is in existence at a
time.
Inefficiently the critical section contains almost the entire blur function so only one thread can
actually run at a time
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
