Answered step by step
Verified Expert Solution
Link Copied!

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 (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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. Information that comes most readily to mind (availability).

Answered: 1 week ago

Question

2. How should this be dealt with by the organisation?

Answered: 1 week ago

Question

explain what is meant by the term fair dismissal

Answered: 1 week ago