ECE344 Lab Assignment on Synchronization Primitives and Problems

operating systems ece344 n.w
1 / 7
Embed
Share

"Explore the ECE344 lab assignment focusing on implementing synchronization primitives like locks and condition variables, solving synchronization problems, and tackling scenarios like mice and cats dining. Dive into the details of operation code and learn about avoiding starvation issues in the system."

  • ECE344
  • Synchronization
  • Operating Systems
  • Lab Assignment
  • Primitives

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Operating Systems ECE344 Lab assignment 1: Synchronization Ding Yuan

  2. Overview of the lab assignment Task 1: implementing synchronization primitives 1a: implement lock 1b: implement condition variable Task 2: use synchronization primitives to solve problems 2a: Mice and cats 2b: traffic lights Ding Yuan, ECE344 Operating System 2

  3. Lock and cond. var. V(sem) { Disable interrupts; sem->count++; thread_wakeup (sem); /* this will wake up all the threads waiting on this sem. Why wake up all threads? */ Enable interrupts; } P(sem) { Disable interrupts; while (sem->count == 0) { thread_sleep(sem); /* current thread will sleep on this sem */ } sem->count--; Enable interrupts; } Needs atomic region Atomic region can be done in a similar way to semaphore If you understand how semaphore is implemented, should be trivial! Cannot use semaphore to implement lock or cond. var. Ding Yuan, ECE344 Operating System 3

  4. Synchronization problems How to start? First: write operation code Next: carefully reason about all the possible interleaving and timing scenarios Add synchronization Ding Yuan, ECE344 Operating System 4

  5. Mice and cats Two bowls, multiple cats and mice Safety criteria: If a cat is eating at either dishes, no mouse can eat If a mouse is eating at either dishes, no cat can eat Ding Yuan, ECE344 Operating System 5

  6. Operation code void sem_eat(const char *who, int num, int bowl, int iteration) { kprintf("%s: %d starts eating: bowl %d, iteration %d\n", who, num, bowl, iteration); clocksleep(1); kprintf("%s: %d ends eating: bowl %d, iteration %d\n", who, num, bowl, iteration); } void mousesem(void * p, unsigned long mousenumber) { int bowl, iteration; for (iteration = 0; iteration < 4; iteration++) { sem_eat ( mouse", mousenumber, bowl, iteration); } } int catmousesem(.. ..) { for (index = 0; index < NCATS; index++) thread_fork("catsem Thread , NULL, index, catsem, NULL); for (index = 0; index < NMICE; index++) thread_fork( mousesem Thread , NULL, index, mousesem, NULL); } Ding Yuan, ECE344 Operating System 6

  7. About starvation You do not need to consider priority or starvation e.g., mice can prevent cat from eating Since cats/mice will eventually finish eating, won t starve forever Ding Yuan, ECE344 Operating System 7

Related


More Related Content