Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions threads/synch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,37 @@ 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() {}
void Lock::Acquire() {}
void Lock::Release() {}
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
}

Condition::Condition(const char* debugName) { }
Condition::~Condition() { }
Expand Down
5 changes: 5 additions & 0 deletions threads/synch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down