Group

Argument Passing

Data Structures

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

Algorithms

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?

  1. At process_execute, we copy the command line and get the executable name
  2. We create a new func for pushing args into stack.
  3. Then we deal with command line in start_process.
    1. In start_process, the input is an complete command line string.
    2. We limit the max command line arguments as 128
    3. We use strtok_r to parse the command line string.
    4. We push the arguments string on stack, and save the pointer of them in argv. (int argc and int argv[] to record the number of arguments and the address of each argument)

Rational

A3: Why does Pintos implement strtok_r() but not strtok()?

PintOS implement strtok_r() instead of strtok() have several reasons: