Skip to content

Add missing locks in console.c and proc.c #222

Closed
ahilaan wants to merge 2 commits intocodenet:p21-locksfrom
ahilaan:lock-fixes
Closed

Add missing locks in console.c and proc.c #222
ahilaan wants to merge 2 commits intocodenet:p21-locksfrom
ahilaan:lock-fixes

Conversation

@ahilaan
Copy link
Copy Markdown

@ahilaan ahilaan commented Mar 14, 2026

This PR adds the missing locks to console.c and proc.c, as mentioned in #214 :

Changes made in console.c:

  • Added locking in consoleintr() around shared console input buffer state
  • Ensured consoleintr() releases the console lock before calling procdump()
  • Added locking in consolewrite() to serialize console output

Changes made in proc.c:

  • Fixed allocproc() failure paths so p->state = UNUSED is updated under ptable.lock

Notes:

  • I did not add cons.lock around the waiting loop in consoleread(). If consoleread() holds cons.lock while waiting for input.r != input.w, then consoleintr() cannot acquire the same lock to insert new input into the buffer, thus creating a deadlock.
  • All files have not been checked thoroughly for missing locks in this PR, so they may need to be added in subsequent PRs

@codenet
Copy link
Copy Markdown
Owner

codenet commented Mar 14, 2026

Hey, actually the locks that you added in proc.c are unnecessary as we made the process EMBRYO within the lock. Two instruction sequences shall not reach found with the same p.

I also removed locks from interrupt handlers such as consoleintr as interrupts are anyways disabled inside interrupt handlers. I added locks in consolewrite here: d0b7ccd

cc @illuminati2285

@codenet codenet closed this Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants