Your SlideShare is downloading. ×
Os Practical Assignment 1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Os Practical Assignment 1

1,294
views

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,294
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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*/
  • 6. Dining philosophers
  • 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.
  • 11. some possible solutions
  • 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.
  • 17. Gracias porsuatencion
    :)