mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.63k stars 2.4k forks source link

Process locks for killed #53

Open mtvec opened 3 years ago

mtvec commented 3 years ago

struct proc::killed is listed among the variables for which struct proc::lock should be held when used. However, this lock is almost invariably not held when killed is read, and it's also not held when written by usertrap.

As far as I can see, the xv6 book does not discuss this issue. I was wondering whether this is a deliberate choice or an oversight.

I believe, with low confidence, that this is not an issue. As far as I can see, it could only ever be a problem if killed is read as 1 while it is actually 0. Since the value of killed is monotonic during a process' lifetime (it only changes from 0 to 1), this seems impossible to happen even if writes to it are not atomic.

Is this assessment correct? If so, I think it would be nice to clarify this both in the source code and in the book.