Download presentation
Presentation is loading. Please wait.
Published byEmory Patterson Modified over 6 years ago
1
Homework Assignment #2 J. H. Wang Oct. 25, 2016
2
Homework #2 Chap.4: 4.3, 4.17*, 4.18* Chap.5: 5.8, 5.19, 5.22
Programming projects for Chap. 4* (*2) Chap.5: 5.8, 5.19, 5.22 Chap.6: 6.11, 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. 8, 2016)
3
Chap. 4 4.3: Which of the following components of a program state are shared across threads in a multithreaded process? (a) Register values (b) Heap memory (c) Global variables (d) Stack memory
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. 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.
12
5.22: Consider two processes, P1 and P2, where p1=50, t1=25, p2=75, and t2=30. (a) Can these two processes be scheduled using rate-monotonic scheduling? Illustrate your answer using a Gantt chart such as the ones in Fig (b) Illustrate the scheduling of these two processes using earliest-deadline-first (EDF) scheduling.
13
Chap.6: 6.11: Assume that a system has multiple processing cores. For each of the following scenarios, describe which is a better locking mechanism – a spinlock or a mutex lock where waiting processes sleep while waiting for the lock to become available: (a) The lock is to be held for a short duration. (b) The lock is to be held for a long duration. (c) A thread may be put to sleep while holding the lock.
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?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.