OperatingSystemsFirstPracticalAssignment<br />Team OS-Project-EVA<br />Emmanuel Alejandro García Solís - 1450138<br />Maxi...
Implementation of Locks<br />synch.cc<br />synch.h<br />Lock::Lock(constchar* debugName) {    name = debugName;    semapho...
Implementation of Locks<br />synch.cc<br />synch.h<br />boolLock::IsHeldByCurrentThread(){    returnlockHolder == currentT...
Implementation of C. V.<br />synch.cc<br />Condition::Condition(constchar* debugName, Lock* conditionLock){     name = deb...
Implementation of C. V.<br />synch.cc<br />voidCondition::Signal(Lock *conditionLock) {    Semaphore *waiter;    ASSERT(co...
Dining philosophers<br />
Dining philosophers<br />In computer science, the dining philosophers problem is an example problem often used in concurre...
Deadlock <br />Refers to a specific condition when two or more processes are each waiting for the other to release a resou...
some possible solutions<br />
By cyclic turn<br />By Several turns.<br />Established several turns. To make it clear, we suppose each philosopher has a ...
By Several turns<br />Established several turns. To make it clear, we suppose each philosopher has a token while is eating...
Gracias porsuatencion<br />:)<br />
Upcoming SlideShare
Loading in...5
×

Os Practical Assignment 1

1,333

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,333
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Os Practical Assignment 1

  1. 1. OperatingSystemsFirstPracticalAssignment<br />Team OS-Project-EVA<br />Emmanuel Alejandro García Solís - 1450138<br />Maximiliano Hernández Castillo - 1453557<br />Adán de Jesús Silva Cuéllar - 1462847<br />http://os-projecteva.blogspot.com/<br />
  2. 2. Implementation of Locks<br />synch.cc<br />synch.h<br />Lock::Lock(constchar* debugName) {    name = debugName;    semaphore = new Semaphore("lock", 1);    lockHolder = NULL;}Lock::~Lock() {    deletesemaphore;}voidLock::Acquire() {    semaphore->P();    lockHolder = currentThread;}<br />classLock { <br />public: <br />Lock(constchar*debugName); <br /> ~Lock(); <br />voidAcquire(); <br />voidRelease(); <br />boolIsHeldByCurrentThread() <br />booltryAcquire();<br />private: <br />constchar* name; Thread *lockHolder; Semaphore *semaphore;<br />};<br />
  3. 3. Implementation of Locks<br />synch.cc<br />synch.h<br />boolLock::IsHeldByCurrentThread(){    returnlockHolder == currentThread;}voidLock::Release() {    ASSERT(IsHeldByCurrentThread());    lockHolder = NULL;    semaphore->V();}<br />boolLock::tryAcquire(){<br />if(lockHolder == NULL){<br />semaphore->P();<br />lockHolder = currentThread;<br />return true;<br /> }<br />else{<br />return false;<br /> }<br />}<br />classLock { <br />public: <br />Lock(constchar*debugName); <br /> ~Lock(); <br />voidAcquire(); <br />voidRelease(); <br />boolIsHeldByCurrentThread() <br />booltryAcquire();<br />private: <br />constchar* name; Thread *lockHolder; Semaphore *semaphore;<br />};<br />/*AlmostthesamethanAcquire(), exceptthat, ifsomeone has thelock, itwillreturnimmediatelyinstead of waiting*/<br />
  4. 4. Implementation of C. V.<br />synch.cc<br />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; }<br />/*Queuecontainingallocated<br />Semaphoresforeachwaitingthread*/<br />/*<br />Checksifthecurrentthread has thelock.<br />Creates a semaphore, initially 0.<br />Addsthesemaphoretothequeue.<br />Releasesthelock, and goestosleepuntil<br />someonesends a Signal.<br />Whensomeonesends a Signal, reaquiresthe<br />lock and deletesthesemaphore*/<br />
  5. 5. Implementation of C. V.<br />synch.cc<br />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);    }}<br />/*Checksifthethecurrentthread<br />has thelock*/<br />/*Ifit’s true, removesthelastsemaphorefromthe<br />waitqueue, assignsittothewaitersemaphore,<br /> and calls V, towakehim up*/<br />/* Wake up allthreadswaitingonthiscondition<br />untilthewaitqueueisempty*/<br />
  6. 6. Dining philosophers<br />
  7. 7. Dining philosophers<br />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.<br />
  8. 8.
  9. 9. Deadlock <br />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.<br />
  10. 10.
  11. 11. some possible solutions<br />
  12. 12. By cyclic turn<br />By Several turns.<br />Established several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, he<br />gives his token to the next philosopher at his right.<br />
  13. 13.
  14. 14. By Several turns<br />Established several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, he<br />gives his token to the next philosopher at his right.<br />
  15. 15.
  16. 16.
  17. 17. Gracias porsuatencion<br />:)<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×