From 38258bc9b47ccaa6328dde59f8a1b638df59b26d Mon Sep 17 00:00:00 2001 From: rjime071 <99309702+rjime071@users.noreply.github.com> Date: Fri, 30 Sep 2022 21:56:25 -0400 Subject: [PATCH 1/2] Set Up for Exercise 2 --- threads/synch.cc | 4 +++- threads/synch.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/threads/synch.cc b/threads/synch.cc index 7d5e3e4..cb8c7df 100644 --- a/threads/synch.cc +++ b/threads/synch.cc @@ -100,7 +100,9 @@ Semaphore::V() // Dummy functions -- so we can compile our later assignments // Note -- without a correct implementation of Condition::Wait(), // the test case in the network assignment won't work! -Lock::Lock(const char* debugName) {} +Lock::Lock(const char* debugName) { + free = true; +} Lock::~Lock() {} void Lock::Acquire() {} void Lock::Release() {} diff --git a/threads/synch.h b/threads/synch.h index 5b6ee14..14bd587 100644 --- a/threads/synch.h +++ b/threads/synch.h @@ -80,6 +80,11 @@ class Lock { private: char* name; // for debugging // plus some other stuff you'll need to define + //We need a queue, similar to that of Semaphore + List *queue; // threads waiting on lock to become free + //Need to know if the lock is free(avaliable) + bool free; //Checks if lock is free + }; // The following class defines a "condition variable". A condition From 50711580eb860b44d25ca22e58f160ed8e78b2bf Mon Sep 17 00:00:00 2001 From: rjime071 <99309702+rjime071@users.noreply.github.com> Date: Fri, 30 Sep 2022 22:17:42 -0400 Subject: [PATCH 2/2] Update synch.cc --- threads/synch.cc | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/threads/synch.cc b/threads/synch.cc index cb8c7df..4d9bf3a 100644 --- a/threads/synch.cc +++ b/threads/synch.cc @@ -101,11 +101,36 @@ Semaphore::V() // Note -- without a correct implementation of Condition::Wait(), // the test case in the network assignment won't work! Lock::Lock(const char* debugName) { + name = debugName; free = true; + queue = new List; +} +Lock::~Lock() { + delete queue; +} +void Lock::Acquire() { + + // Disable interrupts -- similar to Semaphore P() + + //Check if lock is free and then make it unfree + + //Else check if lock is not free -- add self to queue (while to check for free) + + //Enable Interrupts + +} +void Lock::Release() { + + // Disable interrupts + + //Check if thread has lock... isHeldByCurrentThread? + + //if not, do nothing + + //if yes, release the lock and wakeup 1 of the waiting thread in queue + + //Enable interrupts } -Lock::~Lock() {} -void Lock::Acquire() {} -void Lock::Release() {} Condition::Condition(const char* debugName) { } Condition::~Condition() { }