-
Notifications
You must be signed in to change notification settings - Fork 0
Home
P. Ross Baldwin edited this page Apr 12, 2016
·
2 revisions
Welcome to the POS1 wiki!
Ross's notes below: Pintos Project 1 - Alarm
Design Document:
- Need a list struct to hold a queue of currently sleeping threads ** Put the list in timer.c -> initialize the new thread_sleep_list in timer_init()
- thread_sleep() will INTR_OFF and call thread_block with the current thread.
thread.h
- Add attribute struct list_elem sleeplistelem to struct thread?
- Added attribute wait_until_ticks to the thread struct header, which is the current clock + ticks when thread_sleep is called. Used static int64_t, since that is what is used in timer.c for 'ticks'.
- TODO ** ADD DECLARATION line for list_less_func my_less_func; implement in thread.c
thread.c
- thread_block ** thread_block has to be entered with INTR_OFF. It assignes the current thread to THREAD_BLOCKED and calls the scheduler, which calls switch_threads with any thread with a status != THREAD_RUNNING. ** Threads to be sleeped will be put on the sleep list during a call to timer_sleep(). Threads must be inserted into a list in order, to reduce the overhead of searching the sleep_list on every timer tick (There is still the issue that a call to list_insert_ordered() runs an O(n) sort on EVERY CALL). The thread is then passed to thread_block and the scheduler().
timer.c
- instantiate a new 'enum intr_level' (following convention in rest of the code base) and grab the old interrupt level, and call intr_disable().
list_less_func() :
Semaphore way:
- Use a Semaphore to hold the sleeping threads, as the struct semaphore already contains a "struct list waiters".
good funcs sema_up(struct semaphore *sema) -> intr_disable(); schedule(); thread_block(); -> sets status blocked, calls scheduler thread_unblock(); -> puts it on the ready_list, disables INTR and sets prev level on way out