Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework Assignment #2 J. H. Wang Oct. 24, 2017.

Similar presentations


Presentation on theme: "Homework Assignment #2 J. H. Wang Oct. 24, 2017."— Presentation transcript:

1 Homework Assignment #2 J. H. Wang Oct. 24, 2017

2 Homework #2 Chap.4: 4.11, 4.17*, 4.18* Chap.5: 5.8, 5.12, 5.19
Programming projects for Chap. 4* (*2) Chap.5: 5.8, 5.12, 5.19 Chap.6: 6.6, 6.23, 6.33* Programming projects for Chap. 6* (*3) (*: programming exercises) Note: at least one programming exercises or end-of-chapter programming projects must be done and submitted Due: two weeks (Nov. 7, 2017)

3 Chap. 4 4.11: As described in Section 4.7.2, Linux does not distinguish between processes and threads. Instead, Linux treats both in the same way, allowing a task to be more akin to a process or a thread depending on the set of flags passed to the clone() system call. However, other operating systems, such as Windows, treat processes and threads differently. Typically, such systems use a notation in which the data structure for a process contains pointers to the separate threads belonging to the process. Contrast these two approaches for modeling processes and threads within the kernel.

4 4.17*: An interesting way of calculating  is to use a technique known as Monte Carlo, which involves randomization. This technique works as follows: Suppose you have a circle inscribed within a square, as shown in Figure (Assume that the radius of this circle is 1.)

5 First, generate a series of random points as simple (x,y) coordinates
First, generate a series of random points as simple (x,y) coordinates. These points must fall within the Cartesian coordinates that bound the square. Of the total number of random points that are generated, some will occur within the circle. Next, estimate  by performing the following calculation:  =4*(number of points in circle)/(total number of points) (…to be continued)

6 (…continued from the previous slide) Write a multithreaded version of this algorithm that creates a separate thread to generate a number of random points. The thread will count the number of points that occur within the circle and store the result in a global variable. When this thread has exited, the parent thread will calculate and output the estimated value of .

7 4.18*: Repeat exercise 4.17, but instead of using a separate thread to generate random points, use OpenMP to parallelize the generation of points. Be careful not to place the calculation of  in the parallel region, since you want to calculate  only once.

8 Chap.5: 5.8: The following processes are being scheduled using a preemptive round-robin scheduling algorithm. Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. In addition to the processes listed below, the system also has an idle task (which consumes no CPU resources and is identified as Pidle). This task has priority 0 and is scheduled whenever the system has no other available processes to run. (… to be continued)

9 The length of a time quantum is 10 units
The length of a time quantum is 10 units. If a process is preempted by a higher-priority process, the preempted process is placed at the end of the queue. (… to be continued) Thread Priority Burst Arrival P1 40 20 P2 30 25 P3 P4 35 15 60 P5 5 10 100 P6 105

10 (a) Show the scheduling order of the processes using a Gantt chart
(a) Show the scheduling order of the processes using a Gantt chart. (b) What is the turnaround time for each process? (c) What is the waiting time for each process? (d) What is the CPU utilization rate?

11 5.12: Consider a system running ten I/O-bound tasks and one CPU-bound task. Assume that I/O-bound tasks issue an I/O operation once for every millisecond of CPU computing and that each I/O operation takes 10 milliseconds to complete. Also assume that the context-switching overhead is 0.1 millisecond and that all processes are long-running tasks. What is the CPU utilization for a round-robin scheduler when: (a) The time quantum is 1 millisecond (b) The time quantum is 10 millisecond

12 5. 19: Assume that two tasks A and B are running on a Linux system
5.19: Assume that two tasks A and B are running on a Linux system. The nice values of A and B are -5 and +5, respectively. Using the CFS scheduler as a guide, describe how the respective values of vruntime vary between the two processes given each of the following scenarios: (a) Both A and B are CPU-bound. (b) A is I/O-bound, and B is CPU-bound. (c) A is CPU-bound, and B is I/O-bound.

13 Chap.6: 6.6: The Linux kernel has a policy that a process cannot hold a spinlock while attempting to acquire a semaphore. Explain why this policy is in place.

14 6.23: How does the signal() operation associated with monitors differ from the corresponding operation defined for semaphores?

15 6.33*: Exercise 4.17 asked you to design a multithreaded program that estimated pi using the Monte Carlo technique. In that exercise, you were asked to create a single thread that generated random points, storing the result in a global variable. Once that thread exited, the parent thread performed the calculation that estimated the value of pi. Modify that program so that you create several threads, each of which generates random points and determines if the points fall within the circle. Each thread will have to update the global count of all points that fall within the circle. Protect against race conditions on updates to the shared global variable by using mutex locks.

16 End-of-Chapter Programming Projects
Programming Project for Chap. 4: Project 1. Sudoku solution validator Passing parameters to each thread Returning results to the parent thread Project 2. Multithreaded sorting application

17 End-of-Chapter Programming Projects
Programming Projects for Chap. 6: Project 1: The Sleeping Teaching Assistant Room: 1 desk with a chair and computer Hallway: 3 chairs POSIX threads, mutex locks, and semaphores Project 2: The Dining Philosophers Problem Pthread mutex locks and condition variables Project 3: Producer-Consumer Problem Producer and consumer threads Pthreads mutex locks/semaphores Windows mutex locks/semaphores

18 Any Question or Comments?


Download ppt "Homework Assignment #2 J. H. Wang Oct. 24, 2017."

Similar presentations


Ads by Google