home tutorials faq contact
CS tutorials Share you information

Lab 1: Tutorial

This is ONLY a preview of the tutorial. If you would like to view the entire tutorial, you must purchase the tutorial.

Implementing Locks

Provided: the public interface to locks in synch.h 

You: define the private data and implement the interface only need to modify synch.h and synch.cc should not need to modify the public parts of synch.h.

Note: that it should not take you very much code to implement locks. (Hint: You may find semaphores and primitive thread routines useful as building blocks).

Why Do We Need Locks...? to avoid race conditions to make sure that two processes do not get into each other's way when accessing a common resource to sequence the processes when there are dependencies among them

Solution...? mutual exclusion

...

//----------------------------------------------------------------------
// Lock::Acquire
//	Atomically wait until the lock is free, then set it to busy.
//	Equivalent to Semaphore::P(), with the semaphore value of 0
//	equal to busy, and semaphore value of 1 equal to free.
//----------------------------------------------------------------------

void Lock::Acquire()
{
#ifdef CHANGED
  // someone else is holding the lock and its priority is less than mine
  if(debug->IsEnabled(dbgSynch)){
    if (lockHolder!=NULL){
      cout<<"The lock is owned by: "<getName();
    }else {cout<<"\nLock is free\n";}
  }

  if(lockHolder!=NULL &&
     (lockHolder->getPriority() < kernel->currentThread->getPriority())){
    // bump up its priority
    lockHolder->SetPriority(kernel->currentThread->getPriority());
    lockHolder->changed=TRUE;    // set the boolean flag
  }
#endif
  semaphore->P();		 // go to SLEEP until lock FREE
  lockHolder = kernel->currentThread;

}

This is ONLY a preview of the tutorial. If you would like to view the entire tutorial, you must purchase the tutorial.

Each tutorial comes with the following:

  • Assignment overview. Details on each topic in a general level and how they are implemented in Nachos.

  • Walk-through. A complete step-by-step guide on how to implement the code necessary to complete each assignment.

  • Frequently asked questions. Questions and answers to common problems students face while completing each assignment.

  • Helpful links. Links to academic and other websites that offer Nachos assistance and documentation.

  • Documentation. Detailed documentation listing all of the classes, structures, functions defined in Nachos.

  • Roadmap. High-level overview of the source code, focusing on the big picture rather than on the details.

  • Source code. The source code solution to each assignment.

This includes both documentation on understanding the concepts for each assignment and how to get started. Topics are accompanied with animations.

All 5 Assignments Tutorial Package

$149.99
Save 40%

Thread Synchronization Assignment Tutorial

$29.99

Multiprogramming and System Calls Assignment Tutorial

$49.99

Virtual Memory Assignment Tutorial

$49.99

Distributed Networking Assignment Tutorial

$39.99

File System Assignment Tutorial

$39.99

Nachos
Tutorials
Roadmap
Source Code

Introduction
Threads
Interrupts
Synchronization
System Calls
Exception Handling
Multiprogramming
File System
Networking

Tutorials
Lab 1 Tutorial
Lab 2 Tutorial
Lab 3 Tutorial
Lab 4 Tutorial
Lab 5 Tutorial


© 1999-2008 - All rights reserved. CS tutorials™ and the logo are registered trademarks of CS tutorials.