SlideShare a Scribd company logo
1 of 5
OS CLASS TEAM DianaMarcoEverDavid
Unbounded buffer Producer-Consumer with locks In this solution the producer is free to create items at any time, the consumer doesn't care. But if the consumer want to take an item, it needs to check the amount of items in stock, if the amount is zero, it will do nothing.
Unbounded buffer Producer-Consumer with locks function: producer start repeat on true l->Acquire();                  createItem(); in_stock++; l->Release();      end function: consumer start repeat on true         if in_stock == 0            Do nothing         else in_stock > 0 l->Acquire();            destroyItem(); in_stock--; l->Release(); end Lock: l integer: in_stock function: main start in_stock = 0       call producer();        call consumer(); end
Implementing locks in NachOS using Semaphores class SemaphoreLock KernelThread: LockHolder = null; ThreadQueue: waitQueue; function: SemaphoreAcquire   start      bool: status = Interrupt nachos machine.       check if the current thread have this lock.       thread =  current thread        if lockHolder != null           waitQueue = waitfor(thread);       then sleep the thread.       else           waitQueue.acquire(thread);           lockHolder = current thread;       restore the nachos machine with the new status;   end function: SemaphoreRelease   start     bool: status = Interrupt nachos machine     if waitQueue is not empty         lockHolder(current thread) is ready to run now   end end
Implement a condition variable in NachOS using semaphores. Lock cl; SemaphoreLinkedList waitQueue; function: Constructor(Lock *cl) start  conditionLock = cl; waitQueue = getSemaphoreLinkedList(); end function: sleep start  check if the current thread has the lock  sleeper = new Semaphore();  add sleeper to the WaitQueue    cl->release();  sleeper.P()  cl-> acquire(); end function: wake start  check if the current thread has the lock  if waitQueue is not empty           Remove the first thread && use V(); end function: wakeall start   check if the current thread has the lock         repeat until the WaitQueue are empty     call wake(); end

More Related Content

What's hot

Sockets in nach0s
Sockets in nach0sSockets in nach0s
Sockets in nach0s
naniix21_3
 
JavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak Typing
Janlay Wu
 

What's hot (20)

Loops
LoopsLoops
Loops
 
cpanfileがRubyでパースできることに気づいた俺たちは
cpanfileがRubyでパースできることに気づいた俺たちはcpanfileがRubyでパースできることに気づいた俺たちは
cpanfileがRubyでパースできることに気づいた俺たちは
 
Fine grain process control 2nd nov
Fine grain process control 2nd novFine grain process control 2nd nov
Fine grain process control 2nd nov
 
Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)
 
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184
 
Sockets in nach0s
Sockets in nach0sSockets in nach0s
Sockets in nach0s
 
The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202
 
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-CGrand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.
 
New feature of async fakeAsync test in angular
New feature of async fakeAsync test in angularNew feature of async fakeAsync test in angular
New feature of async fakeAsync test in angular
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
devday2012
devday2012devday2012
devday2012
 
Exception Handling in Scala
Exception Handling in ScalaException Handling in Scala
Exception Handling in Scala
 
Boost statechart library
Boost statechart libraryBoost statechart library
Boost statechart library
 
NinjaSynch
NinjaSynchNinjaSynch
NinjaSynch
 
Rust
RustRust
Rust
 
EasyMock 101
EasyMock 101EasyMock 101
EasyMock 101
 
JavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak Typing
 
ReactJS Component Lifecycle hooks with examples
ReactJS Component Lifecycle hooks with examples ReactJS Component Lifecycle hooks with examples
ReactJS Component Lifecycle hooks with examples
 
The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.9 book - Part 92 of 210The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.9 book - Part 92 of 210
 

Similar to Theorical 1

Java 5 concurrency
Java 5 concurrencyJava 5 concurrency
Java 5 concurrency
priyank09
 
I Need Serious Help with this assignment. Plenty Points to be earned.pdf
I Need Serious Help with this assignment. Plenty Points to be earned.pdfI Need Serious Help with this assignment. Plenty Points to be earned.pdf
I Need Serious Help with this assignment. Plenty Points to be earned.pdf
ahntagencies
 
Concurrent Collections Object In Dot Net 4
Concurrent Collections Object In Dot Net 4Concurrent Collections Object In Dot Net 4
Concurrent Collections Object In Dot Net 4
Neeraj Kaushik
 

Similar to Theorical 1 (20)

Java 5 concurrency
Java 5 concurrencyJava 5 concurrency
Java 5 concurrency
 
Introduction+To+Java+Concurrency
Introduction+To+Java+ConcurrencyIntroduction+To+Java+Concurrency
Introduction+To+Java+Concurrency
 
concurrency_c#_public
concurrency_c#_publicconcurrency_c#_public
concurrency_c#_public
 
Python multithreading
Python multithreadingPython multithreading
Python multithreading
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Javascript
JavascriptJavascript
Javascript
 
Java util concurrent
Java util concurrentJava util concurrent
Java util concurrent
 
Testing the waters of iOS
Testing the waters of iOSTesting the waters of iOS
Testing the waters of iOS
 
Thread syncronization
Thread syncronizationThread syncronization
Thread syncronization
 
Multithreading Presentation
Multithreading PresentationMultithreading Presentation
Multithreading Presentation
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
 
Theoretical presentation1nachos
Theoretical presentation1nachosTheoretical presentation1nachos
Theoretical presentation1nachos
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
I Need Serious Help with this assignment. Plenty Points to be earned.pdf
I Need Serious Help with this assignment. Plenty Points to be earned.pdfI Need Serious Help with this assignment. Plenty Points to be earned.pdf
I Need Serious Help with this assignment. Plenty Points to be earned.pdf
 
04 threads
04 threads04 threads
04 threads
 
10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst Tips
 
Concurrent Programming in Java
Concurrent Programming in JavaConcurrent Programming in Java
Concurrent Programming in Java
 
Android Loaders : Reloaded
Android Loaders : ReloadedAndroid Loaders : Reloaded
Android Loaders : Reloaded
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-x
 
Concurrent Collections Object In Dot Net 4
Concurrent Collections Object In Dot Net 4Concurrent Collections Object In Dot Net 4
Concurrent Collections Object In Dot Net 4
 

Recently uploaded

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 

Recently uploaded (20)

Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 

Theorical 1

  • 1. OS CLASS TEAM DianaMarcoEverDavid
  • 2. Unbounded buffer Producer-Consumer with locks In this solution the producer is free to create items at any time, the consumer doesn't care. But if the consumer want to take an item, it needs to check the amount of items in stock, if the amount is zero, it will do nothing.
  • 3. Unbounded buffer Producer-Consumer with locks function: producer start repeat on true l->Acquire(); createItem(); in_stock++; l->Release(); end function: consumer start repeat on true if in_stock == 0 Do nothing else in_stock > 0 l->Acquire(); destroyItem(); in_stock--; l->Release(); end Lock: l integer: in_stock function: main start in_stock = 0 call producer(); call consumer(); end
  • 4. Implementing locks in NachOS using Semaphores class SemaphoreLock KernelThread: LockHolder = null; ThreadQueue: waitQueue; function: SemaphoreAcquire start bool: status = Interrupt nachos machine. check if the current thread have this lock. thread = current thread if lockHolder != null waitQueue = waitfor(thread); then sleep the thread. else waitQueue.acquire(thread); lockHolder = current thread; restore the nachos machine with the new status; end function: SemaphoreRelease start bool: status = Interrupt nachos machine if waitQueue is not empty lockHolder(current thread) is ready to run now end end
  • 5. Implement a condition variable in NachOS using semaphores. Lock cl; SemaphoreLinkedList waitQueue; function: Constructor(Lock *cl) start conditionLock = cl; waitQueue = getSemaphoreLinkedList(); end function: sleep start check if the current thread has the lock sleeper = new Semaphore(); add sleeper to the WaitQueue cl->release(); sleeper.P() cl-> acquire(); end function: wake start check if the current thread has the lock if waitQueue is not empty Remove the first thread && use V(); end function: wakeall start check if the current thread has the lock repeat until the WaitQueue are empty call wake(); end