proj0
Just find and replace… It is better to read the code through though.
proj1
1.1
In alarm.java
, make current thread wait for some interval. Just need an external structure to store the thread according to the priority. And in timerInterrupt()
to wake them up if current time is larger than the designated time for each thread.
Note that the structure involves read and write at the same time, need to disable interrupt before handle it, or use some concurrent structure maybe.
1.2
Need to has an external variable to record in which thread the join has been called. And a counter to record how many times has been called. But this is too cumbersome, since it involves atomicity. Maybe just test whether the join thread has been set or not.
1.3
Condition.java
implements conditional variable (CV) using semaphores. Just open Semaphore.java
and copy paste all the code into Condition2.java
… Just kidding. Basicly, you do the samething. Use a simpler interrupt on a wait queue for threads trying to get the conditional variables. Think about that, when you wait
(sleep
) on some variables in one thread, need to put this thread into the wait queue. When others finished (call wake
), then make this thread ready. Done.
Wait… Is that simple? What is the relationship with lock
? Each CV has a lock. When wait
(sleep
) for some CV, you need first release the lock, let next thread N
on the wait queue for the lock be ready. Then let the current thread C
to sleep, put C
on the wait queue for the conditional variable. Then let N
acquire the lock, and do things.
It is a little complicated… Let’s think it fundementally. CV is a high level of synchronize primitive, which combines Lock with signal process. When you release the lock, you also signal
others you are free. Put others on the wait queue for the lock to be ready. So when you wait for the conditional variables, you do not need to constantly check if the lock is free. Instead, you use a signal procedure to avoid this spinning waiting. Here is a helpful stack overflow link. differences-between-conditional-variables-mutexes-and-locks
1.4
Geoff’s homework is GameMatch, which is really geoff style. It does basicly the samething for locks and conditions. First N-1
players are waiting, then the N
th player comes to wake them all, and increase the match counter. The description is not so clear, so I assume it is first come, first serve order. However it is hard for testing if there are multiple rounds of matches.
proj 2
Since it involves mips gcc
which can not run on my stupid macintosh, I switch to the ubuntu on my pc.
2.1 file system calls
Implement calls creat
, open
, read
, write
, close
, and unlink
, as specified in test/syscall.h
.
Let’s do it step by step. Startring from the simple ones.
Personally I feel open
, close
are the simplest ones, from the length of description lol. You need to create a file descriptor table, to hold the fd
. size is specified as 16. To read the file name, your need to call APIs, like readVirtualMemoryString
in UserProcess
.
read()
, write
should consider many corner cases; like what if read failed, or read only 0 byte, which might be failure, or just no read. ?
unlink()
: let fs handle the problem of multiple open files
support multiprogramming
questions:
- what should be done, if there is not enough page for the process? My current solution is to allocate pages one by one, if receives an error in the process, free all allocated pages for the process.
Reference
[1] Nachos related document. Especially nachos javadoc for walk through the APIs.