Question: with the help of code explain 2 and 3 questions I need clearly The monte-carlo approximation of works as follows: generated inside a square with

 with the help of code explain 2 and 3 questions I

need clearly The monte-carlo approximation of works as follows: generated inside a

square with side length 2. Second, the fraction of those points which

are also inside a unit circle entirely inside the square is calculated.

with the help of code explain 2 and 3 questions I need clearly

The monte-carlo approximation of works as follows: generated inside a square with side length 2. Second, the fraction of those points which are also inside a unit circle entirely inside the square is calculated. This fraction approximately equal to the fraction: [area of circle] / [area of square-m" / 4r2(r-1), The third step multiplies this fraction by 4 to estimate t. First, several random points are 2. Describe how the monte-carlo approximation of T can be altered to use multiple threads. Your solution must: Have each thread/process except one generate random points inside a square with a side length of 2, calculate the fraction of the points inside the unit circle, and store the result in an array Have the other thread/process average the fractions stored in the array and multiply by 4 Use exactly one semaphore. Use the semaphore to create a synchronization barrier so that the threads which generate random points and calculate fractions complete before the thread that averages those fractions begins its task. a. b. c. d. Explain (using a trace of execution) how starvation can occur using the corrected code for the readers-writers problem 3. tinclude #include #include #include #include #include #include #include #include #define true 1 #de fine false 0 //this program illustrates the readers writers //problem. (the first problem) /o reader is kept waiting unless there is a writer writing //2nd problem is writers write as soon as possible /o reader can start if a writer is waiting. sem t rw mutex //for controlling access to data being read/written sem t rc mutex; //for controlling access to read count. int read count; pthread t readerl, reader2, writerl: //readers and writer. void void reader (void) //reader program writer (void )i //writer program int shared data; int main) ( //initialize things... read count 0; sem init (&rw mutex, 0, 1) sem init (&rc mutex, 0, 1) pthread create (&readerl, NULL, reader, NULL) pthread create (&reader2, NULL, reader, NULL) pthread create (&writerl, NULL, writer, NULL) pthread join (readerl, NULL) pthread join (reader2, NULL) pthread join(writerl, NULL) sem destroy (&rw mutex)a sem_destroy (&rw mutex return 0 void reader (void ptr) int i; for (i = 0; i

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!