9.7 Exercises
-
1.
Implement counting semaphores in xv6. Choose a few of xv6’s uses of sleep and wakeup and replace them with semaphores. Judge the result.
-
2.
Can you implement a variant of sleep() that takes just one argument, the channel, and doesn’t need a lock argument?
-
3.
Fix the race mentioned above between
killandsleep, so that akillthat occurs after the victim’s sleep loop checksp->killedbut before it callssleepresults in the victim abandoning the current system call. -
4.
Design a plan so that every sleep loop checks
p->killedso that, for example, a process that is in the virtio driver can return quickly from the while loop if it is killed by another process.