Disable/Enable Interrupts - PowerPoint PPT Presentation

disable enable interrupts n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Disable/Enable Interrupts PowerPoint Presentation
Download Presentation
Disable/Enable Interrupts

play fullscreen
1 / 10
Disable/Enable Interrupts
126 Views
Download Presentation
garry
Download Presentation

Disable/Enable Interrupts

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Disable/Enable Interrupts • Disable_interrupts(); • <<< critical section >>> • Enable_interrupts();

  2. Test-and-Set • TS (<mem loc>) • { • if (<memloc> == 0) • { • <mem loc> = 1; • return 0; • } • else • { • return 1; • }

  3. Mutex: Spin Lock • Acquire_mutex(<mutex>) /* Before entering critical section */ • { • while(TS(<mutex>)) • } • Release_mutex(<mutex>) /* After exiting critical section */ • { • <mutex> = 0; • }

  4. Compare-and-Swap • CS (<mem loc>, <expected value>, <new value>) { • if (<memloc> == <expected value>)) • { • <mem loc> = <new value>; • return 0; • } • else • { • return 1; • } • /* Note: TS(x) == CS (x, 0, 1) -- TS is special case of CS */

  5. Mutex: Spin Lock • Acquire_mutex(<mutex>) /* Before entering critical section */ • { • while (CS (<mutex>, 1, 0)) • ; • } • Release_mutex(<mutex>) /* After exiting critical section */ • { • <mutex> = 1; • }

  6. Counting Semaphore - Semantics • /* proberen – test *. • P(sem) • { • while (sem <= 0) • ; • sem = sem - 1; • } • /* verhogen – to increment */ • V(sem) • { • sem = sem + 1; • }

  7. Counting Semaphore (Non-blocking) Implementation • P (csem) { • while (1) { • Acquire_mutex (csem.mutex); • if (csem.value <= 0) { • Release_mutex (csem.mutex); • continue; • } • else { • csem.value = csem.value – 1; • Release_mutex (csem.mutex); • break; • } • } • }

  8. Counting Semaphore (Non-blocking) Implementation • V (csem) • { • Acquire_mutex (csem.mutex); • csem.value = csem.value + 1; • Release_mutex (csem.mutex); • }

  9. Counting Semaphore (Blocking) Implementation • P (csem) { • while (1) { • Acquire_mutex (csem.mutex); • if (csem.value <= 0) { • insert_queue (getpid(), csem.queue); • Release_mutex_and_block (csem.mutex); /* atomic: lost wake-up */ • } • else { • csem.value = csem.value – 1; • Release_mutex (csem.mutex); • break; • } • } • }

  10. Counting Semaphore (Blocking) Implementation • V (csem) • { • Acquire_mutex (csem.mutex); • csem.value = csem.value + 1; • dequeue_and_wakeup (csem.queue) • Release_mutex (csem.mutex); • }