Operating systems

732 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
732
On SlideShare
0
From Embeds
0
Number of Embeds
300
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Operating systems

  1. 1. Operating systems Carmen Suárez Abraham Silva Gaby García
  2. 2. Problem unbounded-bufer (producer- consumer)Producer and Consumer share a common bufferBut not everything is happiness and perfection...
  3. 3. The producer tries to get to the buffer and addelements but it’s already full
  4. 4. The consumer tries to get to the buffer but it’sempty
  5. 5. When the producer and the consumer go to sleep, and dontreceive calls from anyone. A deadlock occurs Producer Consumer
  6. 6. The solution to this problem is:The use of semaphores or locks. A semaphore will regulatethe production and the consuming of the buffer, givingaccess to only one process at a time. http://bit.ly/rlGtNe
  7. 7. Pseudocodedefine N 100typedef int semaphore;semaphore mutex = 1; void consumer(void){semaphore empaty = N; int element:semaphore full = 0; while(true){void producer(void){ down(full);int element; down(mutex);while(true){ element=down_element();element = produce_element();down(empaty); up(mutex);down(full); up(empaty);insert_element(element); consum_element(element)-,up(mutex); }up(full);} }}
  8. 8. http://bit.ly/rlGtNe
  9. 9. Dining Philosophers
  10. 10. First "possible" solution#define N 5void filosofo(int i){while(TRUE){• think• take left fork• take right fork• eat• leave left fork• leave right fork}}
  11. 11. Deadlock• All of the philosophers are holding a fork while waiting for other fork to be released.• There are no forks available anymore.• They can’t eat because they need two forks.• Starvation
  12. 12. Eliminate deadlocks• TryAcquire• Release all the locks, wait and then reacquire them in the right order• Order the locks: Establish a time for locks
  13. 13. Solution
  14. 14. Suspension algorithmsThere are three components of the time used in a process:• Spinning: It’s the time the thread takes to check whether the lock is available or not. During this time the process is not executing.• Suspending: Is the amount of time the thread is suspended or sleeping, waiting for the lock to be available• Resuming: Is the amount of time the thread takes to restart the execution after acquiring the lock.
  15. 15. Optimal algorithm• The lock is released in less than the suspend and resume time, the process spins until it acquires the lock.
  16. 16. Optimal Algorithm• The lock is released in more than the suspend and resume time, the process should suspend immediately.
  17. 17. Other worse algorithm than SR• if it spins for more than suspend and resume time, then suspend. The worst case is when lock is free after a thread start the suspension. The SR algorithm will cost the suspend and resume time but will spin less time than this algorithm.
  18. 18. Bibliography• Martin Rinard OS Notes http://people.csail.mit.edu/rinard/osnotes/• Sistemas Operativos Modernos, Andrew S. Tanenbaum, 3rd Ed, Prentice Hall.• Dining philosophers imageHTTP://UPLOAD.WIKIMEDIA.ORG/WIKIPEDIA/COMMONS/THUMB/6/6A/DINING_ PHIL OSOPHERS.PNG/200PX-DINING_PHILOSOPHERS.PNG• Deadlock image http://www.cs.rpi.edu/academics/courses/fall04/os/c10/deadlock2.gif
  19. 19. Gracias por su atencion Blog: http://os-sistemasoperativos.blogspot.com

×