Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

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

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Finding and scheduling appointments with new prospective clients.

Answered: 1 week ago