Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chien-Chung Shen CIS/UD

Similar presentations


Presentation on theme: "Chien-Chung Shen CIS/UD"— Presentation transcript:

1 Chien-Chung Shen CIS/UD cshen@udel.edu
Final Exam Review Chien-Chung Shen CIS/UD

2 Zombie When a parent process does not (get the chance to) do a wait() call for its children, the children will become zombie processes (marked by <defunct> in Linux or Z) when they exit /usa/cshen/public_html/361/Proj_3/zombie.c

3 Scheduling Time quantum (slice) Context switching overhead
CPU time of process Multi-level feedback queue zyBooks: Exercises – 3.3.4

4 Course-grained Locking
int count; int salary; // shared var’s mutex_lock A; thread 1 thread 2 lock(A); lock(A); count+=1; count+=2; salary+=50; salary+=70; unlock(A); unlock(A); count+=1; salary+=50; count+=2; salary+=70; How to allow more threads to execute (more) different critical sections at the same time? How to increase concurrency? count+=1; salary+=50; count+=2; salary+=70;

5 Fine-grained Locking count+=1; salary+=50; count+=2; salary+=70; int count; int salary; // shared var’s mutex_lock thread 1 thread 2 lock(A); lock(A); count+=1; count+=2; unlock(A); unlock(A); lock(B); lock(B); salary+=50; salary+=70; unlock(B); unlock(B); A, B; allow more threads to execute (more) different critical sections at the same time count+=1; salary+=50; count+=2; salary+=70;

6 Semaphore Usage: Summary
Mutual exclusion: binary semaphore as mutex lock Controlled access to a given resource consisting of a finite number of instances: counting semaphore semaphore is initialized to the number of instances available Synchronization: two concurrent running threads T1 and T2 with statements S1 and S2, respectively require S2 be executed only after S1 has completed (on one CPU) Semaphore s = 0; T1: S1; signal(s); T2: wait(s); S2; S1 S2 T1 T2

7 Two threads on one CPU ➡️ either thread could run first
initially empty int sem_wait(sem_t *s) { // P s--; if (s < 0) sleep; } int sem_post(sem_t *s) { // V s++; if (threads waiting) wake one up; P buffer C empty = 1 full = 0 What does P care (when will P have to wait)? P waits for buffer to become empty in order to put data into it does it have to wait initially? what should P do after putting data in? notify C that buffer is full What does C care (when will C have to wait)? C waits for buffer to become full (filled) before getting data what should C do after getting data? notify P that buffer is empty sem_wait(&empty); P put(i); sem_post(&full); sem_wait(&full); tmp = get(); C When P looks at the buffer (initially empty), what does it care? Or when will P have to wait? every time it has to wait for something, use a semaphore Does it have to wait initially? When C looks at the buffer (initially empty), what does it care? Or when will C have to wait? sem_post(&empty); Two threads on one CPU ➡️ either thread could run first

8 Efficiency and Concurrency
Behavior of bounded-buffer producer consumer system on a single CPU? Essentially a stop-and-wait protocol (one put followed by one get) many context switching between threads How to increase its efficiency (or reduce # of context switches)? How to increase concurrency (parallelism)? multiple producers and multiple consumers P buffer C

9 Single P/C + Multiple Slots
empty = N = ? full = 0 = ?

10 Rendezvous via Semaphore
/usa/cshen/361/OSTEP/Chap31/HW-Threads-RealSemaphores/r.c

11 $ ln Chapter3 Chapter3.hard $ ls –il (show attributes of files)
two names for the same file $ ln Chapter3 Chapter3.hard $ ls –il (show attributes of files)

12 Get Info about Files [cisc361:/usa/cshen/ ] echo hello > foo [cisc361:/usa/cshen/ ] more foo hello [cisc361:/usa/cshen/ ] stat foo   File: 'foo'   Size: 6         Blocks: 3          IO Block: regular file Device: 29h/41d Inode:       Links: 1 Access: (0664/-rw-rw-r--)  Uid: ( 4157/   cshen)   Gid: ( 4157/   cshen) Access: :06: Modify: :08: Change: :08: Birth: - [cisc361:/usa/cshen/ ] ls -i foo 73985 foo [cisc361:/usa/cshen/ ]  All info of each file is stored in the inode (persistent) structure

13 Soft/Symbolic Links $ ln –s Chapter3 Chapter3.soft Soft link is a file itself containing “pathname” for the file that the link file is a symbolic link to 3 files types regular file (-) directory (d) symbolic link (l)

14 Symbolic (Soft) Links A symbolic link is actually a file itself, of a different type, containing the pathname of the linked-to file d: directory -: regular file l: symbolic link Possible of dangling reference

15 Fundamental Issues Since we cannot count on simultaneous observations of global states in distributed systems, we need to find a property on which we can depend Distributed systems are causal the cause precedes the effect sending of a message precedes the receipt of the message

16 time Space-Time diagram p1 and r4? p3 and q3? concurrent causal

17 Lamport Timestamps Example
Events occurring at three processors local logical clocks are initialized to 0 2 3 7 1 6 4 3 1 5


Download ppt "Chien-Chung Shen CIS/UD"

Similar presentations


Ads by Google