00001 #include <cstdio>
00002 #include <unistd.h>
00003
00004 #include "DynThreads.hh"
00005
00006
00007 class clUserThreads
00008 {
00009 volatile bool bRun;
00010 public:
00011 clUserThreads ()
00012 { bRun = true; }
00013 void *Thread1 (void *);
00014 void *Thread2 (void *);
00015 void *Thread3 (void *);
00016 void Stop ()
00017 { bRun = false; }
00018 };
00019
00020
00021 int main (int argc, char *argv[])
00022 {
00023 int iTime = 0;
00024 int iTId1, iTId2;
00025 clUserThreads UserThreads;
00026 clDynThreads<clUserThreads> DynThreads(UserThreads);
00027
00028 puts("Creating threads...");
00029 iTId1 = DynThreads.Create(&clUserThreads::Thread1, NULL);
00030 iTId2 = DynThreads.Create(&clUserThreads::Thread2, NULL);
00031 DynThreads.Create(&clUserThreads::Thread3, NULL, true);
00032
00033 puts("Threads created, running for 15 seconds...");
00034 while (iTime < 15)
00035 {
00036 sleep(1);
00037 iTime++;
00038 }
00039 UserThreads.Stop();
00040 puts("Waiting for threads to terminate...");
00041
00042 DynThreads.Wait(iTId2);
00043
00044 return 0;
00045 }
00046
00047
00048 void *clUserThreads::Thread1 (void *vpParam)
00049 {
00050 while (bRun)
00051 {
00052 puts("Thread1");
00053 sleep(1);
00054 }
00055 return NULL;
00056 }
00057
00058
00059 void *clUserThreads::Thread2 (void *vpParam)
00060 {
00061 while (bRun)
00062 {
00063 puts("Thread2");
00064 sleep(1);
00065 }
00066 return NULL;
00067 }
00068
00069
00070 void *clUserThreads::Thread3 (void *vpParam)
00071 {
00072 while (bRun)
00073 {
00074 puts("Thread3");
00075 sleep(1);
00076 }
00077 return NULL;
00078 }