Main Page   Compound List   File List   Compound Members   File Members  

threadtest.cc

Go to the documentation of this file.
00001 // threadtest.cc 
00002 //      Simple test case for the threads assignment.
00003 //
00004 //      Create two threads, and have them context switch
00005 //      back and forth between themselves by calling Thread::Yield, 
00006 //      to illustratethe inner workings of the thread system.
00007 //
00008 // Copyright (c) 1992-1993 The Regents of the University of California.
00009 // All rights reserved.  See copyright.h for copyright notice and limitation 
00010 // of liability and disclaimer of warranty provisions.
00011 
00012 #include "copyright.h"
00013 #include "system.h"
00014 
00015 //----------------------------------------------------------------------
00016 // SimpleThread
00017 //      Loop 5 times, yielding the CPU to another ready thread 
00018 //      each iteration.
00019 //
00020 //      "which" is simply a number identifying the thread, for debugging
00021 //      purposes.
00022 //----------------------------------------------------------------------
00023 
00024 void
00025 SimpleThread(int which)
00026 {
00027     int num;
00028     
00029     for (num = 0; num < 5; num++) {
00030         printf("*** thread %d looped %d times\n", which, num);
00031         currentThread->Yield();
00032     }
00033 }
00034 
00035 //----------------------------------------------------------------------
00036 // ThreadTest
00037 //      Set up a ping-pong between two threads, by forking a thread 
00038 //      to call SimpleThread, and then calling SimpleThread ourselves.
00039 //----------------------------------------------------------------------
00040 
00041 void
00042 ThreadTest()
00043 {
00044     DEBUG('t', "Entering SimpleTest");
00045 
00046     Thread *t = new Thread("forked thread");
00047 
00048     t->Fork(SimpleThread, 1);
00049     SimpleThread(0);
00050 }
00051 

Generated on Mon Feb 10 09:54:48 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees