Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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