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
PPTX
Loop control structure
PPT
Mca ii os u-2 process management & communication
PDF
Ia+ threading
PPTX
C# Loops
Operating systems
Operating systems
Operating systems
Loop control structure
Mca ii os u-2 process management & communication
Ia+ threading
C# Loops

What's hot (20)

PPTX
Semophores and it's types
PPTX
Presentation on nesting of loops
PDF
CS844 U1 Individual Project
DOCX
Exception handlingpdf
PPSX
C lecture 4 nested loops and jumping statements slideshare
PDF
Os unit 3
PPT
Iteration
PPT
Looping in c++
PPTX
Nested loop in C language
PPTX
Comp ppt (1)
PDF
Control flow
DOCX
Mcs 041.1
PPTX
Looping statement
PPTX
Loops c++
PPT
Chap05
PDF
Control statements
PPTX
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
DOC
Jumping statements
PPTX
Semophores and it's types
Presentation on nesting of loops
CS844 U1 Individual Project
Exception handlingpdf
C lecture 4 nested loops and jumping statements slideshare
Os unit 3
Iteration
Looping in c++
Nested loop in C language
Comp ppt (1)
Control flow
Mcs 041.1
Looping statement
Loops c++
Chap05
Control statements
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Jumping statements
Ad

Similar to Operating systems (20)

PPT
Operating systems
PPTX
Full solution to bounded buffer
PPT
Exception Handling1
PDF
Network security applications network protocol R
PDF
Let's Talk Locks!
PPT
Handling
PDF
Wait for your fortune without Blocking!
PDF
how to write loops in java explained vividly
PPT
Exception handling and templates
PPT
Lec7!JavaThreads.ppt
PPT
Lec7!JavaThreads.ppt java multithreading
PPT
Exception handling
PPT
12 doloops
DOCX
Java 5 concurrency
PPTX
Java Multithreading.pptx
PPTX
Phasers to stunning
PDF
Storm Real Time Computation
PPTX
Templates
PPTX
Non blocking programming and waiting
Operating systems
Full solution to bounded buffer
Exception Handling1
Network security applications network protocol R
Let's Talk Locks!
Handling
Wait for your fortune without Blocking!
how to write loops in java explained vividly
Exception handling and templates
Lec7!JavaThreads.ppt
Lec7!JavaThreads.ppt java multithreading
Exception handling
12 doloops
Java 5 concurrency
Java Multithreading.pptx
Phasers to stunning
Storm Real Time Computation
Templates
Non blocking programming and waiting
Ad

More from Jonathan Alvarado (12)

ODP
Firma digital
ODP
Android + Bluetooth + Arduino
ODP
Presentacion moviles
PDF
Practical presentation
PPT
Practical presentation
PPT
Practical presentation
PPT
Practical presentation
PPT
Practical presentation
ODP
Avance de Proyecto
PPTX
Avance de Proyecto
ODP
Avance de Proyecto
ODP
Avance de Proyecto
Firma digital
Android + Bluetooth + Arduino
Presentacion moviles
Practical presentation
Practical presentation
Practical presentation
Practical presentation
Practical presentation
Avance de Proyecto
Avance de Proyecto
Avance de Proyecto
Avance de Proyecto

Recently uploaded (20)

PDF
Hybrid model detection and classification of lung cancer
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPT
Geologic Time for studying geology for geologist
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPT
What is a Computer? Input Devices /output devices
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
August Patch Tuesday
PDF
Getting Started with Data Integration: FME Form 101
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Architecture types and enterprise applications.pdf
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
Hybrid model detection and classification of lung cancer
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Geologic Time for studying geology for geologist
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
What is a Computer? Input Devices /output devices
Assigned Numbers - 2025 - Bluetooth® Document
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
August Patch Tuesday
Getting Started with Data Integration: FME Form 101
A review of recent deep learning applications in wood surface defect identifi...
Architecture types and enterprise applications.pdf
Web Crawler for Trend Tracking Gen Z Insights.pptx
observCloud-Native Containerability and monitoring.pptx
A novel scalable deep ensemble learning framework for big data classification...
O2C Customer Invoices to Receipt V15A.pptx
Final SEM Unit 1 for mit wpu at pune .pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions

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