P21: Implementation of Hardware Spinlocks and Basic Concurrency#214
Merged
codenet merged 1 commit intocodenet:p21-spinlocksfrom Mar 14, 2026
Merged
P21: Implementation of Hardware Spinlocks and Basic Concurrency#214codenet merged 1 commit intocodenet:p21-spinlocksfrom
codenet merged 1 commit intocodenet:p21-spinlocksfrom
Conversation
codenet
reviewed
Mar 14, 2026
Owner
codenet
left a comment
There was a problem hiding this comment.
The PR looks very clean. Thanks.
But looks like it is missing locks. Can you carefully check it again?
| consoleintr(int (*getc)(void)) | ||
| { | ||
| int c, doprocdump=0; | ||
|
|
| { | ||
| uint target; | ||
| int c; | ||
|
|
Owner
|
Actually, let me merge it so other students can fix missing locks etc. |
Author
|
Done, I have merged p22-sleeplocks into my branch and manually resolved all the merge conflicts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: I have targeted the p20-exec branch for this PR because the p21 branch does not yet exist in the upstream repo. Once the p21 branch is created, the base branch of this PR can be changed to p21 for merging.
Overview
This PR implements the P21 requirements by introducing basic concurrency controls. I have added hardware spinlocks and protected all core OS data structures to match the
xv6-publicstandard, preventing single-processor interrupt race conditions.Key Implementations:
spinlock.hand implementedacquire/releaselogic utilizing the existingpushcliandpopcliinterrupt controls.kalloc.c: Protected the physical memory allocator (kmem.lock).proc.c: Protected the process table (ptable.lock) and implementedforkretto properly release the scheduler lock for newly allocated processes.bio.c: Protected the block buffer cache (bcache.lock) across all return paths.file.c: Protected the open file table (ftable.lock).fs.c: Protected the inode cache (icache.lock), ensuring the lock is temporarily released before disk I/O iniputto prevent deadlocks duringitrunc.ide.c: Protected the disk request queue (idelock) while safely keeping the wait loop lock-free.console.c,trap.c,log.c: Secured the console (cons.lock), timer ticks (tickslock), and log headers (log.lockvialog_write).(Note:
fileread,filewrite, andconsolereadare intentionally left lock-free as they rely on Sleep Locks, which are planned for P22).