COS 318 Project 2Non-Preemptive SchedulingPrecept 2AgendaQuestions from design review / emailsMiscellaneousGrading criteriaGDB on bochs (CJ Bell)Blocking SemanticsWhen a thread required a LOCKED lock, it gets blocked, not coming back to ready queuewhen a thread releases a lock, it unlocks the first waiting threadlock_release() does not imply do_yield()When a thread is unblocked, it is not executed until all unblocked tasks at the time have yieldedExample Code Thread 1:lock_init(&lock);lock_acquire(&lock);do_yield();lock_release(&lock);do_exit()Thread 4:lock_acquire(&lock);lock_release(&lock);do_exit();Thread 2:while(TRUE) { do_yield();}Thread 3:do_yield();lock_acquire(&lock);lock_release(&lock);do_exit();Example Code Thread 1:lock_init(&lock);lock_acquire(&lock);do_yield();lock_release(&lock);do_exit()Thread 4:lock_acquire(&lock);lock_release(&lock);do_exit();Thread 2:while(TRUE) { do_yield();}Thread 3:do_yield();lock_acquire(&lock);lock_release(&lock);do_exit();T1 acquiresT4 blockedExample Code Thread 1:lock_init(&lock);lock_acquire(&lock);do_yield();lock_release(&lock);do_exit()Thread 4:lock_acquire(&lock);lock_release(&lock);do_exit();Thread 2:while(TRUE) { do_yield();}Thread 3:do_yield();lock_acquire(&lock);lock_release(&lock);do_exit();T1 releasesunblocked T4T3 blockedT4 releasesunblocked T3Lock ImplementationSimple lock implementation: LOCKED, UNLOCKEDDo not have to handle deadlockThink what you should do when:two threads are blocked waiting for the same lock? Follow FIFO ruleSome other process tries to acquire the lock before the unblocked process starts runningPCBPCBs are statically allocated in memory for this projectNo recycling of memory space of any kindstack, pcb, locks.....You may add whatever you feel necessarystart address of a programkernel thread or user processContext Switchingkernel_entry()Used to switch between user process and the kernel for system callssaves and restores user registersscheduler_entry()used to switch between kernel threads and user processes that are in kernelsaves and restores system registersyield() system call (in syslib)goes through kernel_entry() to switch to kernel modegoes through scheduler_entry() to switch to another process/threadExampleProcess P -> Thread Tyield() system call -> kernel_entrysave registers, load kernel stack (working on kernel stack now)do_yield()load user stack, restore user registersdo_yield()enqueue P to ready queuescheduler_entry()save P’s kernel registersscheduler()load T’s kernel registersretFirst time to switch to a taskThere is no return address on stackHow do you find where to return to?ask scheduler to jump to the entry point of the program if it is the first time to runwhat else?Inline AssemblyGeneral format:volatile : _ _asm_ _ volatileflags: refer to the resource page provided on project website_ _asm_ _ (“instruction”“instruction”....“instruction”:”=flags”:”=flags”:”=flags”) ;Grading CriteriaTotal: 10 points + 1 extra credit pointKernel threads and scheduling: 3 pointsProcesses and system calls: 3 pointsMutual exclusion: 2 pointsTiming a context switch: 1 pointCoding style, comments, and README: 1 pointIf your program runs on bochs, but does not run on fishbowl, 1 point penalty at mostGDB for bochsThanks,
View Full Document