OperatingSystemsFirstPracticalAssignmentTeam OS-Project-EVAEmmanuel Alejandro García Solís - 1450138Maximiliano Hernández Castillo - 1453557Adán de Jesús Silva Cuéllar - 1462847http://os-projecteva.blogspot.com/
Implementation of Lockssynch.ccsynch.hLock::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 Lockssynch.ccsynch.hboolLock::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.ccCondition::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; }/*QueuecontainingallocatedSemaphoresforeachwaitingthread*//*Checksifthecurrentthread has thelock.Creates a semaphore, initially 0.Addsthesemaphoretothequeue.Releasesthelock, and goestosleepuntilsomeonesends a Signal.Whensomeonesends a Signal, reaquiresthelock  and deletesthesemaphore*/
Implementation of C. V.synch.ccvoidCondition::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);    }}/*Checksifthethecurrentthreadhas thelock*//*Ifit’s true, removesthelastsemaphorefromthewaitqueue, assignsittothewaitersemaphore, and calls V, towakehim up*//* Wake up allthreadswaitingonthisconditionuntilthewaitqueueisempty*/
Dining philosophers
Dining philosophersIn 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 turnBy Several turns.Established several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, hegives his token to the next philosopher at his right.
By Several turnsEstablished several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, hegives his token to the next philosopher at his right.
Gracias porsuatencion:)

Os Practical Assignment 1

  • 1.
    OperatingSystemsFirstPracticalAssignmentTeam OS-Project-EVAEmmanuel AlejandroGarcía Solís - 1450138Maximiliano Hernández Castillo - 1453557Adán de Jesús Silva Cuéllar - 1462847http://os-projecteva.blogspot.com/
  • 2.
    Implementation of Lockssynch.ccsynch.hLock::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 Lockssynch.ccsynch.hboolLock::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.ccCondition::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; }/*QueuecontainingallocatedSemaphoresforeachwaitingthread*//*Checksifthecurrentthread has thelock.Creates a semaphore, initially 0.Addsthesemaphoretothequeue.Releasesthelock, and goestosleepuntilsomeonesends a Signal.Whensomeonesends a Signal, reaquiresthelock and deletesthesemaphore*/
  • 5.
    Implementation of C.V.synch.ccvoidCondition::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);    }}/*Checksifthethecurrentthreadhas thelock*//*Ifit’s true, removesthelastsemaphorefromthewaitqueue, assignsittothewaitersemaphore, and calls V, towakehim up*//* Wake up allthreadswaitingonthisconditionuntilthewaitqueueisempty*/
  • 6.
  • 7.
    Dining philosophersIn computerscience, the dining philosophers problem is an example problem often used in concurrent algorithm design to illustrate synchronization issues and techniques for resolving them.
  • 9.
    Deadlock Refers toa 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.
  • 11.
  • 12.
    By cyclic turnBySeveral turns.Established several turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, hegives his token to the next philosopher at his right.
  • 14.
    By Several turnsEstablishedseveral turns. To make it clear, we suppose each philosopher has a token while is eating, when he finishes, hegives his token to the next philosopher at his right.
  • 17.