Lecture 10, Locks * demonstrate problem (Ch. 26, x86.py) * simple lock examples (Ch. 28, x86.py) * scalability of concurrent structures (Ch. 29) - global shared counter - sloppy counter (weak/eventual consistency) - concurrent linked list Ch. 28 & 29 of OSTEP (after a quick look back at Ch. 26): Get the .tgz files for Threads Intro) and Threads (Locks) from http://pages.cs.wisc.edu/~remzi/OSTEP/Homework/homework.html (n.b.: They will unpack into the current directory, so create a subdir and cd into it first.) First, demonstrate the problem (examples from Ch. 26): wifi-139-170:ThreadsIntro rdv$ pwd /Users/rdv/Dropbox/old/rdv/keio/sfc/teaching/rdvteachingweb/undergrad-OS/undergrad-OS-2018/ThreadsIntro ./x86.py -p simple-race.s -t 1 ./x86.py -p simple-race.s -t 1 -M 2000 -R ax,bx -c ./x86.py -p looping-race-nolock.s -t 2 -a bx=1 -M 2000 -c ./x86.py -p looping-race-nolock.s -t 2 -a bx=1 -M 2000 -i 2 ./x86.py -p looping-race-nolock.s -t 2 -a bx=1 -M 2000 -i 2 -c ./x86.py -p looping-race-nolock.s -t 2 -a bx=1 -M 2000 -c -R ax,bx ./x86.py -p looping-race-nolock.s -t 2 -a bx=1 -M 2000 -c -R ax,bx -i 2 Now see some possible solutions (from Ch. 28): First, runs okay: ./x86.py -p flag.s -t 2 -a bx=1 -M count -c -R ax,bx But this still doesn't work under all circumstances: ./x86.py -p flag.s -t 2 -a bx=1 -M count -c -R ax,bx -i 2 ./x86.py -p flag.s -t 2 -a bx=2 -M count -c -R ax,bx ./x86.py -p flag.s -t 2 -a bx=3 -M count -c -R ax,bx ./x86.py -p flag.s -t 2 -a bx=3 -M count -c -R ax,bx -i 2 ./x86.py -p flag.s -t 2 -a bx=3 -M count -c -R ax,bx -i 3 Test-and-set example: ./x86.py -p test-and-set.s -t 2 -a bx=2 -M count -c -R ax,bx ./x86.py -p test-and-set.s -t 2 -a bx=2 -M count -c -R ax,bx -i 2 And with three threads: ./x86.py -p test-and-set.s -t 3 -a bx=2 -M count -c -R ax,bx -i 2 ./x86.py -p test-and-set.s -t 3 -a bx=3 -M count -c -R ax,bx -i 2