Recently I was doing MIT6.S081 2021 Fall, and while reading the xv6-riscv documentation, in Chapter 6, Section 5, the discussion of Re-entrant locks, there is an example:
struct spinlock lock;
int data = 0; // protected by lock
f() {
acquire(&lock);
if(data == 0) {
call_once();
h();
data = 1;
}release(&lock);
}
g() {
aquire(&lock);
if(data == 0) {
call_once();
data = 1;
}
release(&lock);
}
In fact, I didn't find a definition for h(). From a context perspective, it should be g() because Re-entrant locks cause call_once() to be called more than twice.
I don't know if I missed it somewhere, but I did think so. If you have any questions, please let me know. thank you.
Here is what I think the version is, along with a screenshot of the original documentation:
struct spinlock lock;
int data = 0; // protected by lock
f() {
acquire(&lock);
if(data == 0) {
call_once();
g(); // here, I guess it is g() not h()
data = 1;
}release(&lock);
}
g() {
aquire(&lock);
if(data == 0) {
call_once();
data = 1;
}
release(&lock);
}
Correct Document(xv6-risc) Errors
Here is what I think the version is, along with a screenshot of the original documentation: