Main Page | Alphabetical List | Class List | File List | Class Members | File Members

threadtest.cc File Reference

#include "copyright.h"
#include "system.h"
#include "synch.h"
#include <time.h>
#include "list.h"

Go to the source code of this file.

Functions

void Ping (int ch)
void Pong (int ch)
void PingPong ()
void SimpleThread1 (int which)
void ThreadTest1 (int arg)

Variables

Semaphore SPing ("Ping", 1)
Semaphore SPong ("Pong", 0)


Function Documentation

void Ping int  ch  ) 
 

Definition at line 19 of file threadtest.cc.

References Semaphore::P(), SPing, SPong, and Semaphore::V().

Referenced by PingPong().

00020 { 00021 printf("Ping Start\n"); 00022 for(int i = 0; i < 10; i++) 00023 { 00024 SPing.P(); 00025 printf("Ping\n"); 00026 SPong.V(); 00027 } 00028 } /* Ping */

void PingPong  ) 
 

Definition at line 43 of file threadtest.cc.

References Thread::Fork(), Ping(), and Pong().

Referenced by ThreadTest1().

00044 { 00045 Thread *t1 = new Thread("Ping"); 00046 Thread *t2 = new Thread("Pong"); 00047 00048 t1->Fork(Ping, 0); 00049 t2->Fork(Pong, 0); 00050 } /* PingPong */

void Pong int  ch  ) 
 

Definition at line 31 of file threadtest.cc.

References Semaphore::P(), SPing, SPong, and Semaphore::V().

Referenced by PingPong().

00032 { 00033 printf("Pong Start\n"); 00034 for(int i = 0; i < 10; i++) 00035 { 00036 SPong.P(); 00037 printf("Pong\n"); 00038 SPing.V(); 00039 } 00040 } /* Pong */

void SimpleThread1 int  which  ) 
 

Definition at line 54 of file threadtest.cc.

Referenced by ThreadTest1().

00055 { 00056 int num4 = 1; 00057 int num = 0; 00058 int count = 0; 00059 00060 printf("^%c Started\n", which); 00061 00062 for (num = 0; num < 500; num++) 00063 { 00064 for(num4 = 0; num4 < 40000; num4++, count++) 00065 ; 00066 printf("%c", (char)which); 00067 count++; 00068 } /* for */ 00069 00070 printf("%c$Done count:%d$\n", which, count); 00071 } /* SimpleThread1 */

void ThreadTest1 int  arg  ) 
 

Definition at line 78 of file threadtest.cc.

References Thread::Fork(), PingPong(), and SimpleThread1().

Referenced by main().

00079 { 00080 printf("Entering SimpleTest\n"); 00081 00082 00083 Thread *t1 = new Thread("A thread"); 00084 Thread *t2 = new Thread("B thread"); 00085 Thread *t3 = new Thread("C thread"); 00086 Thread *t4 = new Thread("D thread"); 00087 Thread *t5 = new Thread("E thread"); 00088 Thread *t6 = new Thread("F thread"); 00089 Thread *t7 = new Thread("G thread"); 00090 t1->Fork(SimpleThread1, 'A'); 00091 t2->Fork(SimpleThread1, 'B'); 00092 t3->Fork(SimpleThread1, 'C'); 00093 t4->Fork(SimpleThread1, 'D'); 00094 t5->Fork(SimpleThread1, 'E'); 00095 t6->Fork(SimpleThread1, 'F'); 00096 t7->Fork(SimpleThread1, 'G'); 00097 00098 printf("Doing Ping Pong\n"); 00099 PingPong(); 00100 } /* ThreadTest1 */


Variable Documentation

Semaphore SPing("Ping", 1)
 

Referenced by Ping(), and Pong().

Semaphore SPong("Pong", 0)
 

Referenced by Ping(), and Pong().


Generated on Thu Sep 16 12:33:47 2004 for NachOS by doxygen 1.3.8