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

Info iconThis preview shows pages 1–2. 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 DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2010 for the course CS CS 503 taught by Professor Zhengpingwu during the Spring '09 term at University of Bridgeport.

Page1 / 3

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online