SlideShare a Scribd company logo
1 of 17
OperatingSystemsFirstPracticalAssignment Team OS-Project-EVA Emmanuel Alejandro García Solís - 1450138 Maximiliano Hernández Castillo - 1453557 Adán de Jesús Silva Cuéllar - 1462847 http://os-projecteva.blogspot.com/
Implementation of Locks synch.cc synch.h Lock::Lock(constchar* debugName) {    name = debugName;    semaphore = new Semaphore("lock", 1);    lockHolder = NULL;}Lock::~Lock() {    deletesemaphore;}voidLock::Acquire() {    semaphore->P();    lockHolder = currentThread;} classLock {   public:   Lock(constchar*debugName);   	~Lock(); 	   voidAcquire();    voidRelease();   boolIsHeldByCurrentThread()  booltryAcquire(); private:    constchar* name;		Thread *lockHolder;    	Semaphore *semaphore; };
Implementation of Locks synch.cc synch.h boolLock::IsHeldByCurrentThread(){    returnlockHolder == currentThread;}voidLock::Release() {    ASSERT(IsHeldByCurrentThread());    lockHolder = NULL;    semaphore->V();} boolLock::tryAcquire(){ if(lockHolder == NULL){ semaphore->P(); lockHolder = currentThread; return true;    } else{ return false;     } } classLock {   public:   Lock(constchar*debugName);   	~Lock(); 	   voidAcquire();    voidRelease();   boolIsHeldByCurrentThread()  booltryAcquire(); private:    constchar* name;		Thread *lockHolder;    	Semaphore *semaphore; }; /*AlmostthesamethanAcquire(), exceptthat, ifsomeone has thelock, itwillreturnimmediatelyinstead of waiting*/
Implementation of C. V. synch.cc Condition::Condition(constchar* debugName, Lock* conditionLock){     name = debugName;    waitQueue = new List<Semaphore *>;}voidCondition::Wait(Lock *conditionLock) {    Semaphore *waiter;    ASSERT(conditionLock>IsHeldByCurrentThread());waiter = new Semaphore("condition", 0);    waitQueue->Append(waiter);    conditionLock->Release();    waiter->P();    conditionLock->Acquire();    deletewaiter; } /*Queuecontainingallocated Semaphoresforeachwaitingthread*/ /* Checksifthecurrentthread has thelock. Creates a semaphore, initially 0. Addsthesemaphoretothequeue. Releasesthelock, and goestosleepuntil someonesends a Signal. Whensomeonesends a Signal, reaquiresthe lock  and deletesthesemaphore*/
Implementation of C. V. synch.cc voidCondition::Signal(Lock *conditionLock) {    Semaphore *waiter;    ASSERT(conditionLock->IsHeldByCurrentThread());    if(!waitQueue->IsEmpty()){        waiter = waitQueue->Remove();        waiter->V();    }}voidCondition::Broadcast(Lock *conditionLock) {    while(!waitQueue->IsEmpty()){        Signal(conditionLock);    }} /*Checksifthethecurrentthread has thelock*/ /*Ifit’s true, removesthelastsemaphorefromthe waitqueue, assignsittothewaitersemaphore,  and calls V, towakehim up*/ /* Wake up allthreadswaitingonthiscondition untilthewaitqueueisempty*/
Dining philosophers
Dining philosophers In computer science, the dining philosophers problem is an example problem often used in concurrent algorithm design to illustrate synchronization issues and techniques for resolving them.
Deadlock  Refers to a specific condition when two or more processes are each waiting for the other to release a resource, or more than two processes are waiting for resources in a circular chain.
some possible solutions
By cyclic turn By Several turns. Established several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, he gives his token to the next philosopher at his right.
By Several turns Established several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, he gives his token to the next philosopher at his right.
Gracias porsuatencion :)

More Related Content

What's hot

Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
Michael Barker
 
20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会
Hiroki Mizuno
 

What's hot (19)

为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
 
Debugging TV Frame 0x09
Debugging TV Frame 0x09Debugging TV Frame 0x09
Debugging TV Frame 0x09
 
Programação completa e perfeira
Programação completa e perfeiraProgramação completa e perfeira
Programação completa e perfeira
 
Robots against robots: How a Machine Learning IDS detected a novel Linux Botn...
Robots against robots: How a Machine Learning IDS detected a novel Linux Botn...Robots against robots: How a Machine Learning IDS detected a novel Linux Botn...
Robots against robots: How a Machine Learning IDS detected a novel Linux Botn...
 
20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会
 
One definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьOne definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим жить
 
Vcs8
Vcs8Vcs8
Vcs8
 
Ravada VDI Eslibre
Ravada VDI EslibreRavada VDI Eslibre
Ravada VDI Eslibre
 
Crash Fast & Furious
Crash Fast & FuriousCrash Fast & Furious
Crash Fast & Furious
 
gemdiff
gemdiffgemdiff
gemdiff
 
Azure Durable Funkiness - .NET Oxford June 2018
Azure Durable Funkiness - .NET Oxford June 2018Azure Durable Funkiness - .NET Oxford June 2018
Azure Durable Funkiness - .NET Oxford June 2018
 
Android taipei 20160225 淺談closure
Android taipei 20160225   淺談closureAndroid taipei 20160225   淺談closure
Android taipei 20160225 淺談closure
 
CROCHET - Checkpoint Rollback in JVM (ECOOP 2018)
CROCHET - Checkpoint Rollback in JVM (ECOOP 2018)CROCHET - Checkpoint Rollback in JVM (ECOOP 2018)
CROCHET - Checkpoint Rollback in JVM (ECOOP 2018)
 
EasyMock 101
EasyMock 101EasyMock 101
EasyMock 101
 
Promises in JavaScript
Promises in JavaScriptPromises in JavaScript
Promises in JavaScript
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
Michael kontopoulos
Michael kontopoulosMichael kontopoulos
Michael kontopoulos
 
it's only abuse if it crashes
it's only abuse if it crashesit's only abuse if it crashes
it's only abuse if it crashes
 

Viewers also liked (8)

Dining philosopher mutex_2
Dining philosopher mutex_2Dining philosopher mutex_2
Dining philosopher mutex_2
 
DPP
DPPDPP
DPP
 
dining philosophers problem using montiors
dining philosophers problem using montiorsdining philosophers problem using montiors
dining philosophers problem using montiors
 
Dining Philosopher's Problem
Dining Philosopher's ProblemDining Philosopher's Problem
Dining Philosopher's Problem
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OS
 
Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphores
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
 
Semaphores
SemaphoresSemaphores
Semaphores
 

Similar to Os Practical Assignment 1

Fault tolerance made easy
Fault tolerance made easyFault tolerance made easy
Fault tolerance made easy
Uwe Friedrichsen
 
Java 5 concurrency
Java 5 concurrencyJava 5 concurrency
Java 5 concurrency
priyank09
 
Unit II Java & J2EE regarding Java application development
Unit II Java & J2EE regarding Java application developmentUnit II Java & J2EE regarding Java application development
Unit II Java & J2EE regarding Java application development
rohitgudasi18
 
Orsiso
OrsisoOrsiso
Orsiso
e27
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 

Similar to Os Practical Assignment 1 (20)

Fault tolerance made easy
Fault tolerance made easyFault tolerance made easy
Fault tolerance made easy
 
Java 5 concurrency
Java 5 concurrencyJava 5 concurrency
Java 5 concurrency
 
Java util concurrent
Java util concurrentJava util concurrent
Java util concurrent
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Theoretical presentation1nachos
Theoretical presentation1nachosTheoretical presentation1nachos
Theoretical presentation1nachos
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special Cases
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()
 
My java file
My java fileMy java file
My java file
 
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
 
exception handling in cpp
exception handling in cppexception handling in cpp
exception handling in cpp
 
Unit II Java & J2EE regarding Java application development
Unit II Java & J2EE regarding Java application developmentUnit II Java & J2EE regarding Java application development
Unit II Java & J2EE regarding Java application development
 
Orsiso
OrsisoOrsiso
Orsiso
 
Locks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael BarkerLocks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael Barker
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Unit testing CourseSites Apache Filter
Unit testing CourseSites Apache FilterUnit testing CourseSites Apache Filter
Unit testing CourseSites Apache Filter
 
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-CGrand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Server1
Server1Server1
Server1
 

More from Emmanuel Garcia (8)

Reporte Project Puddi - Semana 9
Reporte Project Puddi - Semana 9Reporte Project Puddi - Semana 9
Reporte Project Puddi - Semana 9
 
Reporte Project Puddi - Semana 9
Reporte Project Puddi - Semana 9Reporte Project Puddi - Semana 9
Reporte Project Puddi - Semana 9
 
Puddi Semana 7
Puddi Semana 7Puddi Semana 7
Puddi Semana 7
 
Fase 2
Fase 2Fase 2
Fase 2
 
Avance de proyecto
Avance de proyectoAvance de proyecto
Avance de proyecto
 
Presentación Proyecto POO y TPOO
Presentación Proyecto POO y TPOOPresentación Proyecto POO y TPOO
Presentación Proyecto POO y TPOO
 
Proyecto final
Proyecto finalProyecto final
Proyecto final
 
Algoritmo De Dijkstra
Algoritmo De DijkstraAlgoritmo De Dijkstra
Algoritmo De Dijkstra
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Os Practical Assignment 1

  • 1. OperatingSystemsFirstPracticalAssignment Team OS-Project-EVA Emmanuel Alejandro García Solís - 1450138 Maximiliano Hernández Castillo - 1453557 Adán de Jesús Silva Cuéllar - 1462847 http://os-projecteva.blogspot.com/
  • 2. Implementation of Locks synch.cc synch.h Lock::Lock(constchar* debugName) {    name = debugName;    semaphore = new Semaphore("lock", 1);    lockHolder = NULL;}Lock::~Lock() {    deletesemaphore;}voidLock::Acquire() {    semaphore->P();    lockHolder = currentThread;} classLock { public: Lock(constchar*debugName); ~Lock(); voidAcquire(); voidRelease(); boolIsHeldByCurrentThread() booltryAcquire(); private: constchar* name; Thread *lockHolder; Semaphore *semaphore; };
  • 3. Implementation of Locks synch.cc synch.h boolLock::IsHeldByCurrentThread(){    returnlockHolder == currentThread;}voidLock::Release() {    ASSERT(IsHeldByCurrentThread());    lockHolder = NULL;    semaphore->V();} boolLock::tryAcquire(){ if(lockHolder == NULL){ semaphore->P(); lockHolder = currentThread; return true; } else{ return false; } } classLock { public: Lock(constchar*debugName); ~Lock(); voidAcquire(); voidRelease(); boolIsHeldByCurrentThread() booltryAcquire(); private: constchar* name; Thread *lockHolder; Semaphore *semaphore; }; /*AlmostthesamethanAcquire(), exceptthat, ifsomeone has thelock, itwillreturnimmediatelyinstead of waiting*/
  • 4. Implementation of C. V. synch.cc Condition::Condition(constchar* debugName, Lock* conditionLock){     name = debugName;    waitQueue = new List<Semaphore *>;}voidCondition::Wait(Lock *conditionLock) {    Semaphore *waiter;    ASSERT(conditionLock>IsHeldByCurrentThread());waiter = new Semaphore("condition", 0);    waitQueue->Append(waiter);    conditionLock->Release();    waiter->P();    conditionLock->Acquire();    deletewaiter; } /*Queuecontainingallocated Semaphoresforeachwaitingthread*/ /* Checksifthecurrentthread has thelock. Creates a semaphore, initially 0. Addsthesemaphoretothequeue. Releasesthelock, and goestosleepuntil someonesends a Signal. Whensomeonesends a Signal, reaquiresthe lock and deletesthesemaphore*/
  • 5. Implementation of C. V. synch.cc voidCondition::Signal(Lock *conditionLock) {    Semaphore *waiter;    ASSERT(conditionLock->IsHeldByCurrentThread());    if(!waitQueue->IsEmpty()){        waiter = waitQueue->Remove();        waiter->V();    }}voidCondition::Broadcast(Lock *conditionLock) {    while(!waitQueue->IsEmpty()){        Signal(conditionLock);    }} /*Checksifthethecurrentthread has thelock*/ /*Ifit’s true, removesthelastsemaphorefromthe waitqueue, assignsittothewaitersemaphore, and calls V, towakehim up*/ /* Wake up allthreadswaitingonthiscondition untilthewaitqueueisempty*/
  • 7. Dining philosophers In computer science, the dining philosophers problem is an example problem often used in concurrent algorithm design to illustrate synchronization issues and techniques for resolving them.
  • 8.
  • 9. Deadlock Refers to a specific condition when two or more processes are each waiting for the other to release a resource, or more than two processes are waiting for resources in a circular chain.
  • 10.
  • 12. By cyclic turn By Several turns. Established several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, he gives his token to the next philosopher at his right.
  • 13.
  • 14. By Several turns Established several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, he gives his token to the next philosopher at his right.
  • 15.
  • 16.