A1: Copy here the declaration of each new or changed "struct" or "struct" member, global or static variable, typedef, or enumeration. Identify the purpose of each in 25 words or less.
# thread.h
struct semaphore sema;
bool success;
//def for pj2 thread.h
void acquire_file_lock(void);
void release_file_lock(void);
// pj2 thread.c
static struct lock file_lock;
void acquire_file_lock(){
lock_acquire(&file_lock);
}
void release_file_lock(){
lock_release(&file_lock);
}
lock_init(&file_lock);// in thread init
A2: Briefly describe how you implemented argument parsing. How do you arrange for the elements of argv[] to be in the right order? How do you avoid overflowing the stack page?
process_execute, we copy the command line and get the executable nameint because we have alignment requirement.start_process.
start_process, the input is an complete command line string.strtok_r to parse the command line string.argv. (int argc and int argv[] to record the number of arguments and the address of each argument)A3: Why does Pintos implement strtok_r() but not strtok()?
PintOS implement strtok_r() instead of strtok() have several reasons:
strtok(), strtok_r() is designed to be thread-safe as it doesn't rely on a shared static variable to maintain the parsing position within the string.strtok() isn't reentrant because it uses a static variable, strtok_r() achieves reentrancy by accepting a pointer argument to store the current position, enabling multiple independent invocations in multithreaded or recursive contexts.