p1_mythread - MyThread Library 1 Assignment ● Design a...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MyThread Library 1 Assignment ● Design a non-preemptive thread library ● Create the library file: mythead.a ● Use “context” system calls: ○ swapcontext, makecontext, getcontext, … 2 Thread state diagram one thread can be running 3. Wait, join 3 running 1 1. Head of ready Q 5. Create 2 blocked blocked blocked blocked one or more blocked queues 2. Yield ready 4 5 stop when no threads in ready queue 4. Signal, exit (ends join) 3 Plan 1. Understand context routines ○ Write test program that switches between 2 threads 1. Implement create(), yield() 2. Implement fork(), join() 3. Implement semaphores 4 Semaphore ● Semaphore S – integer variable ● Two standard operations modify S: acquire() and release() ○ Originally called P() and V() ● Less complicated ● Can only be accessed via two indivisible (atomic) operations acquire(S) { // also called: wait while (S <= 0) /* no-op */; S--; } release(S) { // also called: signal S++; } 5 Semaphore Implementation ● Must guarantee that no two processes can execute acquire() and release() on the same semaphore at the same time ● Thus implementation becomes the critical section problem ○ Busy waiting (spinlock) in critical section implementation ■ Implementation code is short ■ Little busy waiting if critical section rarely occupied ■ More busy waiting waste of CPU resources ○ Applications may spend lots of time in critical sections ■ Performance issues need to be addressed 6 Semaphore Implementation ● Both operations are atomic acquire(S){ release(S){ value--; value++; if (value < 0) { if (value <= 0) { add this process to list remove a process P from block(this); list } wakeup(P); } } } 7 ...
View Full Document

This note was uploaded on 01/22/2012 for the course COMPUTER S 302 taught by Professor Stewart during the Spring '11 term at N.C. State.

Page1 / 7

p1_mythread - MyThread Library 1 Assignment ● Design a...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online