Race Conditions in List

Race Conditions in List - Race Conditions in List Assume...

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

View Full Document Right Arrow Icon
Race Conditions in List Assume our list did not have mutex locks. We can have the following race condition: Assume T1 calls remove() and T2 calls insert(). Initially 1 _hea d 2 NULL
Background image of page 1

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

View Full DocumentRight Arrow Icon
Race Conditions in List 2. T2 insert(5) 1 _hea d 2 5 2. T2: a) e2- >next=_head NULL 1. T1 remove() 1 _hea d 2 tmp1 1. T1: c) tmp=_head NULL tmp1 3. T2 insert(5) 1 _hea d 2 5 3. T2: b) _head = NULL tmp1 1. T1 remove() 1 _hea d 2 5 4. T1: d)_head=tmp->_next; Node 5 is lost!!! tmp1 NULL ctxswitch ctxswitch E2
Background image of page 2
Drawbacks in the List Class The MT List implementation described before does not behave well if the list is empty (returning –1). We would like an implementation where remove waits if the List is empty. This behavior cannot be implemented with only mutex locks Semaphores are needed to implement this behavior.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Semaphores Semaphores are a generalization of mutexes. A mutex allows only one thread to execute the code guarded by a mutex_lock / mutex_unlock pair. A semaphore allows a maximum number of
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/30/2012 for the course CS 354 taught by Professor Staff during the Fall '08 term at Purdue University.

Page1 / 12

Race Conditions in List - Race Conditions in List Assume...

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

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