Concurrency in Xv6
Locking patterns
Pattern 1: Design locked data structure
Example: The filesystem’s block cache.
Pattern 2: Design locks to run in different threads
Example
// Lock the given inode.
// Reads the inode from disk if necessary.
void
ilock(struct inode *ip)
{
struct buf *bp;
struct dinode *dip;
if(ip == 0 || ip->ref < 1)
panic(“ilock”);
acquiresleep(&ip->lock);
…Pattern 3: How to free an object
Problem
Solution
Example
Lock-like patterns
Example: Filesystem looks up path
Solution
Other lock-like patterns
Protect by implicit structure rather than locks
Disable interrupts
No locks at all
Study Topics
c volatile keyword
volatile keywordParallelism
Last updated