mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.58k stars 2.38k forks source link

Correct Document(xv6-risc) Errors #185

Open ChenMiaoi opened 1 year ago

ChenMiaoi commented 1 year ago

Correct Document(xv6-risc) Errors

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);
}

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);
}

The Document PDF image