Initial version
This commit is contained in:
commit
6f405265a5
102 changed files with 14486 additions and 0 deletions
52
code/threads/threadtest.cc
Normal file
52
code/threads/threadtest.cc
Normal file
|
@ -0,0 +1,52 @@
|
|||
// threadtest.cc
|
||||
// Simple test case for the threads assignment.
|
||||
//
|
||||
// Create two threads, and have them context switch
|
||||
// back and forth between themselves by calling Thread::Yield,
|
||||
// to illustratethe inner workings of the thread system.
|
||||
//
|
||||
// Copyright (c) 1992-1993 The Regents of the University of California.
|
||||
// All rights reserved. See copyright.h for copyright notice and limitation
|
||||
// of liability and disclaimer of warranty provisions.
|
||||
|
||||
#include "copyright.h"
|
||||
#include "system.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// SimpleThread
|
||||
// Loop 10 times, yielding the CPU to another ready thread
|
||||
// each iteration.
|
||||
//
|
||||
// "which" is simply a number identifying the thread, for debugging
|
||||
// purposes.
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void
|
||||
SimpleThread (void *arg)
|
||||
{
|
||||
int which = (long) arg;
|
||||
int num;
|
||||
|
||||
for (num = 0; num < 10; num++)
|
||||
{
|
||||
printf ("*** thread %d looped %d times\n", which, num);
|
||||
currentThread->Yield ();
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// ThreadTest
|
||||
// Set up a ping-pong between two threads, by forking a thread
|
||||
// to call SimpleThread, and then calling SimpleThread ourselves.
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void
|
||||
ThreadTest ()
|
||||
{
|
||||
DEBUG ('t', "Entering SimpleTest\n");
|
||||
|
||||
Thread *t = new Thread ("forked thread");
|
||||
|
||||
t->Start (SimpleThread, (void*) 1);
|
||||
SimpleThread (0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue