SlideShare ist ein Scribd-Unternehmen logo
1 von 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 :)

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
 

Kürzlich hochgeladen (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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...
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 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
 

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.