Throughout this semester, we expect that you will read the entire implementation of the xv6 kernel, accompanied by the xv6 book, which explains the rationale and design underlying the kernel's implementation. (The source code is also available as a Lions-style PDF)
For this lecture, read the following files in the xv6 kernel implementation:
You may find Chapter 7 of the book useful in understanding locking.
In kernel/spinlock.c, comment out or delete these lines in acquire():
while(__sync_lock_test_and_set(&lk->locked, 1) != 0) ;and replace them with
while(*(volatile int *) &lk->locked != 0) ; lk->locked = 1;Use gdb to help explore the result when you boot xv6 and run a few commands, or run usertests. You may have to boot a few times to see a problem. What goes wrong? Why?
Optional challenge question: instead of the previous replacement, try it without "volatile":
while(lk->locked != 0) ; lk->locked = 1;
Now what goes wrong, and why?
Submit your answer in an ASCII text file named homework.txt to the corresponding "Lecture N" assignment on Gradescope.
Questions or comments regarding 6.1810? Send e-mail to the course staff at 61810-staff@lists.csail.mit.edu.