solution for lab3 with nachos
solution for eventBarrier:
in an eventBarrier, we need three queues:one storing threads waiting for signal(waiting), another storing threads that has been signaled and waiting till all waiting threads have been signaled(ready to run).the last storing threads call eventBarrier while eventBarrier is releasing waiting threads(hang up).
a variable named count is required to count the number of threads in the queue of waiting.
a semaphore named signal is used to check if the event happened.(how does a semaphore work, i need to think in details).
another semaphore named status is used to flag the status of eventBarrier,signaled or unsignaled.
then is the implementing of the interfaces of eventBarrier:
wait()---a thread calling wait() will be inserted into queue of waiting,then count++;
signal()---if the event took place,all threads in queue of waiting will be released,and count decrease to be zero.the user must be the thread which the expected event in.blocked till all threads released,and turn satus unsignaled.
complete()---this function may be called by thread in queue of waiting.if called,it inserts the thread into the queue of ready to run.after that,it should be blocked till eventBarrier wakes it up.
waiters()---just return the number of threads in the queue of waiting(if unsignaled).
solution for alarm clock:
isn't ready yet.
solution for problem one, bridge:
isn't ready yet.
solution for problem two, elevator:
isn't ready yet.
in an eventBarrier, we need three queues:one storing threads waiting for signal(waiting), another storing threads that has been signaled and waiting till all waiting threads have been signaled(ready to run).the last storing threads call eventBarrier while eventBarrier is releasing waiting threads(hang up).
a variable named count is required to count the number of threads in the queue of waiting.
a semaphore named signal is used to check if the event happened.(how does a semaphore work, i need to think in details).
another semaphore named status is used to flag the status of eventBarrier,signaled or unsignaled.
then is the implementing of the interfaces of eventBarrier:
wait()---a thread calling wait() will be inserted into queue of waiting,then count++;
signal()---if the event took place,all threads in queue of waiting will be released,and count decrease to be zero.the user must be the thread which the expected event in.blocked till all threads released,and turn satus unsignaled.
complete()---this function may be called by thread in queue of waiting.if called,it inserts the thread into the queue of ready to run.after that,it should be blocked till eventBarrier wakes it up.
waiters()---just return the number of threads in the queue of waiting(if unsignaled).
solution for alarm clock:
isn't ready yet.
solution for problem one, bridge:
isn't ready yet.
solution for problem two, elevator:
isn't ready yet.
0 Comments:
Post a Comment
<< Home