00001
00002
00003
00004
00005
00006
00007
00008
00009
#include "copyright.h"
00010
#include "system.h"
00011
#include "synch.h"
00012
#include <time.h>
00013
#include "list.h"
00014
00015
Semaphore SPing(
"Ping", 1);
00016
Semaphore SPong(
"Pong", 0);
00017
00018
00019 void Ping(
int ch)
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 }
00029
00030
00031 void Pong(
int ch)
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 }
00041
00042
00043 void PingPong()
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 }
00051
00052
00053
00054 void SimpleThread1(
int which)
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 }
00069
00070 printf(
"%c$Done count:%d$\n", which, count);
00071 }
00072
00073
00074
00075
00076
00077
00078 void ThreadTest1(
int arg)
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 }
00101
00102