SlideShare a Scribd company logo
Operating Systems Team: Jonathan Arturo Alvarado Mata   1441616 Obed David  Guevara Ibarra        1447478 Carlos Eduardo Triana Sarmiento    1412573 Blog: http://os-ocj.blogspot.com/
First Point    Explain how to solve unbounded-buffer producer-consumer with locks.    Discuss the quality of the proposed solution.
what we did?... We use an array as global variable, this array contain the number of items. We use this array to control the producer and the consumer, because if the array is full the producer stops producing and if the array is empty the consumer stops consuming Also we use two threads, one for the consumer and the other for the producer.
what we did?... The assignment consists in implementing locks to the producer consumer problem. So we have to declare a lock as a global variable, which controls the threads activity. This is important to remember....   Only the thread that acquired the lock can release it
CODE LOCK *L1; CONDITION *C PRODUCER(){          WHILE(1){ //  try to aquire the lock IF(L1->TRYAQUIRE()){                             // if the array is full, lets wait                           // if it isn’t, continue...                              WHILE(ARRAY == FULL){                                       C->WAIT(L1)                                           }                     // increase the number of items in the array                   C-> SIGNAL(); //  Enables the waiting threads                   L1->RELEASE();  }  // end of if                }  // end of  while         }  // end of the function producer
CONSUMER(){ while(1){ //  try to aquire the lock if(l1->TRYAQUIRE()){ //  if the array is empty, wait                    // if it isn’t, continue...                    WHILE(ARRAY == EMPTY){                               C->WAIT(L1);                                           }  // decrease the number of items in the array               CONSUME();                       C-> SIGNALl();   //  Enables the waiting thread                        L1->RELEASE();           }  // end of if       }  // end of while }  //end of function consumer
void main(){ L1 = new lock(“L1”); C = new condition(“C”); Thread *t = new Thread(“producer”);   t->Fork(producer, 1); Thread * t= new Thread(“consumer”); t->Fork(consumer, 1); }end main
Second Point     Explain how to detect and eliminate deadlock in the dinning philosophers problem.
The solution... *  This is the solution When a philosopher has a fork waits a random time to get the second fork. If in that time is not free the second fork, release the one he has and go back to the queue If a philosopher "A" release a fork (because he has eaten or because he waited too long with a fork in hand) but still want to eat, getting back on line to the fork.   Basically we follow this concept and that's how we make the code
CODE Philosophers[N];     //Array to store the philosophers Lock *L1  // Only two philosophers can try to get 2 forks Lock *L2 void philosopher (i){         WHILE(true){         think();  //All the philosophers start waiting         take_forks(i);      }  //End of while }  //End of function void take_forks(int i){     Look_for_Locks();     Get_Forks();     Eat();     Drop_Forks();       L1->release() || L2 ->release();    //release the lock that the philosophers has       philosopher return to the queue        }  //End of function
  void Look_for_Locks(){     IF(L1->tryaquire() || L2 -> tryaquire()){          if one is available         return to  take_forks     }ELSE{ // if not          wait some time         look if one lock is available and try to get it         if no lock is available             L1-> release() || L2 -> release()         philosopher return to the queue     }//end else }
    void Get_Forks(){     Look for forks;     if(fork == 1 || fork == 0)  // if no Lock is available or if only got one         wait some time         look if forks are available and try to get one or two         if (fork == 2){              return to take_forks      }else{  // if doesn’t get the fork it need          drop fork          L1-> release() || L2 -> release()    // release the lock that the philosophers has          philosopher return to the queue      }else{ return to take_forks } }
Bibliography *Operating Systems-Design and Implementation, Second Edition Author: Andrew S. Tanenbaum and Albert S. Woodhull   * http://www.isi.edu/~faber/cs402/notes/lecture7.html   *http://www.4coders.com/index.php?modulo=contenido&op=detalle&tipo=c&id=83http://www.4coders.com/index.php?modulo=contenido&op=detalle&tipo=c&id=83   *http://es.wikipedia.org/wiki/Problema_de_la_cena_de_los_fil%C3%B3sofos

More Related Content

PPT
Operating systems
PPT
Operating systems
PPT
Operating systems
PPT
Mca ii os u-2 process management & communication
PPTX
Fine grain process control 2nd nov
PDF
Ia+ threading
PPTX
Loop control structure
Operating systems
Operating systems
Operating systems
Mca ii os u-2 process management & communication
Fine grain process control 2nd nov
Ia+ threading
Loop control structure

What's hot (20)

PPTX
Presentation on nesting of loops
PPT
Looping in c++
PPTX
Phasers to stunning
PPTX
C# Loops
PPSX
C lecture 4 nested loops and jumping statements slideshare
PPTX
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
PPT
Iteration
PPTX
Comp ppt (1)
PPTX
Nested loop in C language
PDF
Javascript fundamentals for php developers
PPTX
Looping statement
PDF
PPTX
Loops c++
DOCX
Exception handlingpdf
PDF
Control statements
PPT
Free FreeRTOS Course-Task Management
PDF
Loops in c++
PPTX
Iteration Statement in C++
Presentation on nesting of loops
Looping in c++
Phasers to stunning
C# Loops
C lecture 4 nested loops and jumping statements slideshare
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Iteration
Comp ppt (1)
Nested loop in C language
Javascript fundamentals for php developers
Looping statement
Loops c++
Exception handlingpdf
Control statements
Free FreeRTOS Course-Task Management
Loops in c++
Iteration Statement in C++
Ad

Viewers also liked (20)

PDF
Dining Philosopher's Problem
PPT
Chapter 6 - Process Synchronization
DOCX
Dinning philosopher
PPT
Unit 3 basic processing unit
PPT
My SQl
PPT
IP Addressing
PPT
PPT
Saftey
PPT
PPT
PPT
Shell Script
PPT
I/O Management
PPTX
1. review jurnal effect dwi hastho
PPT
Network Security
PDF
The Dining Philosophers problem in Bangla
PPT
PPT
Denail of Service
PPT
Linux Introduction
PPT
Tractor Components
PPTX
Dining Philosopher's Problem
Chapter 6 - Process Synchronization
Dinning philosopher
Unit 3 basic processing unit
My SQl
IP Addressing
Saftey
Shell Script
I/O Management
1. review jurnal effect dwi hastho
Network Security
The Dining Philosophers problem in Bangla
Denail of Service
Linux Introduction
Tractor Components
Ad

Similar to Operating systems (20)

PPT
Operating systems
PDF
Operating systems
PDF
Operating systems
PPT
Unbounded
PPS
Unbounded
PPT
PPTX
Full solution to bounded buffer
PPTX
Theorical 1
PPTX
Teorical 1
PPT
Process Synchronization
PPTX
Theorical 1
ODP
Theoretical presentation1nachos
PPT
Process synchronization(deepa)
PPTX
Producer consumer
DOCX
Implementing of classical synchronization problem by using semaphores
PPTX
Teorical1
DOCX
Critical section operating system
PPT
Classical-Problem-of-Synchronization in OS
DOCX
Java 5 concurrency
Operating systems
Operating systems
Operating systems
Unbounded
Unbounded
Full solution to bounded buffer
Theorical 1
Teorical 1
Process Synchronization
Theorical 1
Theoretical presentation1nachos
Process synchronization(deepa)
Producer consumer
Implementing of classical synchronization problem by using semaphores
Teorical1
Critical section operating system
Classical-Problem-of-Synchronization in OS
Java 5 concurrency

More from Eduardo Triana (12)

PPT
1 internetworking
PPT
1 internetworking
PDF
Redes final
PDF
Redes proyecto
PDF
PicSumador
PDF
NachOS 3 - Practical presentation
PDF
Nachos3 - Theoretical Part
PDF
Nachos 2 Practical Part
PPT
Nachos 2 Practical Part
PPT
Nachos 2 Practical Part
PPT
Nachos Extra Points
PPT
Nachos 2
1 internetworking
1 internetworking
Redes final
Redes proyecto
PicSumador
NachOS 3 - Practical presentation
Nachos3 - Theoretical Part
Nachos 2 Practical Part
Nachos 2 Practical Part
Nachos 2 Practical Part
Nachos Extra Points
Nachos 2

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Machine learning based COVID-19 study performance prediction
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Machine Learning_overview_presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Tartificialntelligence_presentation.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Getting Started with Data Integration: FME Form 101
A comparative analysis of optical character recognition models for extracting...
Machine learning based COVID-19 study performance prediction
MIND Revenue Release Quarter 2 2025 Press Release
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Advanced methodologies resolving dimensionality complications for autism neur...
Network Security Unit 5.pdf for BCA BBA.
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Assigned Numbers - 2025 - Bluetooth® Document
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine Learning_overview_presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Tartificialntelligence_presentation.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?

Operating systems

  • 1. Operating Systems Team: Jonathan Arturo Alvarado Mata   1441616 Obed David  Guevara Ibarra        1447478 Carlos Eduardo Triana Sarmiento    1412573 Blog: http://os-ocj.blogspot.com/
  • 2. First Point   Explain how to solve unbounded-buffer producer-consumer with locks.    Discuss the quality of the proposed solution.
  • 3. what we did?... We use an array as global variable, this array contain the number of items. We use this array to control the producer and the consumer, because if the array is full the producer stops producing and if the array is empty the consumer stops consuming Also we use two threads, one for the consumer and the other for the producer.
  • 4. what we did?... The assignment consists in implementing locks to the producer consumer problem. So we have to declare a lock as a global variable, which controls the threads activity. This is important to remember.... Only the thread that acquired the lock can release it
  • 5. CODE LOCK *L1; CONDITION *C PRODUCER(){          WHILE(1){ // try to aquire the lock IF(L1->TRYAQUIRE()){                            // if the array is full, lets wait                           // if it isn’t, continue...                             WHILE(ARRAY == FULL){                                       C->WAIT(L1)                                         }                   // increase the number of items in the array                  C-> SIGNAL(); // Enables the waiting threads                   L1->RELEASE(); } // end of if                } // end of  while        } // end of the function producer
  • 6. CONSUMER(){ while(1){ // try to aquire the lock if(l1->TRYAQUIRE()){ // if the array is empty, wait                    // if it isn’t, continue...                    WHILE(ARRAY == EMPTY){                               C->WAIT(L1);                                           } // decrease the number of items in the array               CONSUME();                       C-> SIGNALl(); // Enables the waiting thread                        L1->RELEASE();           } // end of if       } // end of while } //end of function consumer
  • 7. void main(){ L1 = new lock(“L1”); C = new condition(“C”); Thread *t = new Thread(“producer”);   t->Fork(producer, 1); Thread * t= new Thread(“consumer”); t->Fork(consumer, 1); }end main
  • 8. Second Point     Explain how to detect and eliminate deadlock in the dinning philosophers problem.
  • 9. The solution... *  This is the solution When a philosopher has a fork waits a random time to get the second fork. If in that time is not free the second fork, release the one he has and go back to the queue If a philosopher "A" release a fork (because he has eaten or because he waited too long with a fork in hand) but still want to eat, getting back on line to the fork.   Basically we follow this concept and that's how we make the code
  • 10. CODE Philosophers[N];     //Array to store the philosophers Lock *L1 // Only two philosophers can try to get 2 forks Lock *L2 void philosopher (i){         WHILE(true){         think(); //All the philosophers start waiting         take_forks(i);     } //End of while } //End of function void take_forks(int i){     Look_for_Locks();     Get_Forks();     Eat();     Drop_Forks();       L1->release() || L2 ->release();   //release the lock that the philosophers has       philosopher return to the queue      } //End of function
  • 11.   void Look_for_Locks(){     IF(L1->tryaquire() || L2 -> tryaquire()){         if one is available         return to  take_forks     }ELSE{ // if not         wait some time         look if one lock is available and try to get it         if no lock is available             L1-> release() || L2 -> release()         philosopher return to the queue     }//end else }
  • 12.     void Get_Forks(){     Look for forks;     if(fork == 1 || fork == 0) // if no Lock is available or if only got one         wait some time         look if forks are available and try to get one or two         if (fork == 2){             return to take_forks     }else{ // if doesn’t get the fork it need         drop fork         L1-> release() || L2 -> release()    // release the lock that the philosophers has         philosopher return to the queue     }else{ return to take_forks } }
  • 13. Bibliography *Operating Systems-Design and Implementation, Second Edition Author: Andrew S. Tanenbaum and Albert S. Woodhull   * http://www.isi.edu/~faber/cs402/notes/lecture7.html   *http://www.4coders.com/index.php?modulo=contenido&op=detalle&tipo=c&id=83http://www.4coders.com/index.php?modulo=contenido&op=detalle&tipo=c&id=83   *http://es.wikipedia.org/wiki/Problema_de_la_cena_de_los_fil%C3%B3sofos