{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab1 - Lab Assignment 1 Finish the below tasks using the...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab Assignment 1: Finish the below tasks using the language and the programming environment at your choice. (Due on March 9, 2010 2:30pm) 1. Design and implement “lock” and “condition” variables. You may either use semaphores as a building block, or you may use more primitive thread routines, such as Sleep(). When you write the description of your implementation, explain and justify your design. The skeleton code is illustrated below (it is incomplete and may contain errors; correct it by yourself and provide your own solution). Lock::Lock(char* debugName) { name = debugName; owner = NULL; semaphore = new Semaphore("lock",1); } Lock::~Lock() { name = NULL; owner = NULL; delete semaphore; } void Lock::Acquire() { if(owner != currentThread) { semaphore->P(); owner = currentThread; } } void Lock::Release() { ASSERT(isHeldByCurrentThread()); owner = NULL; semaphore->V(); } bool Lock::isHeldByCurrentThread() { return (owner == currentThread); } /////////////////////////////////////////////////// Condition::Condition(char* debugName) { name = debugName; waiting = new List; } Condition::~Condition() { name = NULL;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
delete waiting; } void Condition::Wait(Lock* conditionLock) {
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}