Chien-Chung Shen CIS/UD cshen@udel.edu Final Exam Review Chien-Chung Shen CIS/UD cshen@udel.edu
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
Scheduling Time quantum (slice) Context switching overhead CPU time of process Multi-level feedback queue zyBooks: Exercises 3.3.1 – 3.3.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;
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;
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
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
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
Single P/C + Multiple Slots empty = N = ? full = 0 = ?
Rendezvous via Semaphore /usa/cshen/361/OSTEP/Chap31/HW-Threads-RealSemaphores/r.c
$ 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)
Get Info about Files [cisc361:/usa/cshen/361 1077] echo hello > foo [cisc361:/usa/cshen/361 1078] more foo hello [cisc361:/usa/cshen/361 1079] stat foo File: 'foo' Size: 6 Blocks: 3 IO Block: 1048576 regular file Device: 29h/41d Inode: 73985 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 4157/ cshen) Gid: ( 4157/ cshen) Access: 2018-12-02 23:06:59.243498589 -0400 Modify: 2018-12-02 23:08:42.979511362 -0400 Change: 2018-12-02 23:08:42.979511362 -0400 Birth: - [cisc361:/usa/cshen/361 1080] ls -i foo 73985 foo [cisc361:/usa/cshen/361 1081] All info of each file is stored in the inode (persistent) structure
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)
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
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
time Space-Time diagram p1 and r4? p3 and q3? concurrent causal
Lamport Timestamps Example Events occurring at three processors local logical clocks are initialized to 0 2 3 7 1 6 4 3 1 5