Lecture6 - COP 5611 Operating Systems Spring 2010 Dan C...

Info iconThis preview shows pages 1–8. 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

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: COP 5611 Operating Systems Spring 2010 Dan C. Marinescu Office: HEC 439 B Office hours: M-Wd 2:00-3:00 PM 2 Lecture 6 Last time: Virtualization Today: Thread coordination Scheduling Next Time: Multi-level memories I/O bottleneck Evolution of ideas regarding communication among threads using a bounded buffer 1. Use locks does not address the busy waiting problem 2. YIELD based on voluntary release of the processor by individual threads 3. Use WAIT (for an event ) and NOTIFY (when the event occurs) primitives . 4. Use AWAIT (for an event) and ADVANCE (when the event occurs) 3 Primitives for thread sequence coordination YIELD requires the thread to periodically check if a condition has occurred. Basic idea use events and construct two before-or-after actions WAIT (event_name) issued by the thread which can continue only after the occurrence of the event event_name . NOTIFY (event_name) search the thread_tabl e to find a thread waiting for the occurrence of the event event_name . 4 shared structure buffer message instance message[N] integer in initially integer out initially lock instance buffer_lock initially UNLOCKED event instance room event instance notempty procedure SEND (buffer reference p, message instance msg) ACQUIRE (p_buffer_lock) while p.in – p.out = N do /* if buffer full wait RELEASE (p_buffer_lock) WAIT (p.room) ACQUIRE (p_buffer_lock) p.message [p.in modulo N] ß msg /* insert message into buffer cell if p.in= p.out then NOTIFY(p.notempty) p.in ß p.in + 1 /* increment pointer to next free cell RELEASE (p_buffer_lock) procedure RECEIVE (buffer reference p) ACQUIRE (p_buffer_lock) while p.in = p.out do /* if buffer empty wait for message RELEASE (p_buffer_lock) WAIT (p.notempty) ACQUIRE (p_buffer_lock) msg ß p.message [p.in modulo N] /* copy message from buffer cell if ( p.in- p.out=N) then NOTIFY(p.room) p.out ß p.out + 1 /* increment pointer to next message RELEASE (p_buffer_lock) return msg This solution does not work 6 The NOTIFY should always be sent after the WAIT. If the sender and the receiver run on two different processor there could be a race condition for the notempty event. The NOTIFY could be sent before the WAIT. Tension between modularity and locks Several possible solutions: AWAIT/ADVANCE, semaphores, etc AWAIT - ADVANCE solution A new state, WAITING and two before-or-after actions that take a RUNNING thread into the WAITING state and back to RUNNABLE state. eventcount variables with an integer value shared between threads and the thread manager; they are like events but have a value. A thread in the WAITING state waits for a particular value of the eventcount AWAIT( eventcount,value ) If eventcount >value the control is returned to the thread calling AWAIT and this thread will continue execution If eventcount ≤value the state of the thread calling AWAIT is changed to WAITING and the thread is suspended.and the thread is suspended....
View Full Document

Page1 / 26

Lecture6 - COP 5611 Operating Systems Spring 2010 Dan C...

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

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