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 (i.e., like your homework). Does this
code handle threads efficiently, or inefficiently? Explain.
//Assume that the program compiles and //produces the expected result
pthread_t tids[THREAD_COUNT];
Pixel** input;
Pixel** output;
pthread_mutex_t output_mutex;
//OMITTED: main method that loads file, calls //process_image, and saves the file.
int process_image(){
for(int i=0; i < THREAD_COUNT; i++)
pthread_create(&tids[i], NULL, blur, i);
for(int =0; i < THREAD_COUNT; i++)
pthread_join(&tids[i], NULL);
}
void* blur(void* arg){
pthread_mutex_lock(output_mutex);
//all the filter code goes here and works on //column
pthread_mutex_unlock(output_mutex)
pthread_exit(0);
}
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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!