| 1 | #include "machdefs.h"
 | 
|---|
| 2 | #include "zthread.h"
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include <math.h>
 | 
|---|
| 5 | #include <unistd.h>
 | 
|---|
| 6 | #include <iostream>
 | 
|---|
| 7 | #include <stdexcept>
 | 
|---|
| 8 | 
 | 
|---|
| 9 | //  Include file pour PI 
 | 
|---|
| 10 | #include "pisysdep.h"
 | 
|---|
| 11 | 
 | 
|---|
| 12 | #include PIAPP_H
 | 
|---|
| 13 | #include PIMENU_H 
 | 
|---|
| 14 | #include PISTDWDG_H 
 | 
|---|
| 15 | #include PIWIN_H
 | 
|---|
| 16 | #include PIPERIODIC_H
 | 
|---|
| 17 | #include "picons.h"
 | 
|---|
| 18 | 
 | 
|---|
| 19 | //  Include file Sophya (TArray) 
 | 
|---|
| 20 | #include "tarrinit.h"
 | 
|---|
| 21 | #include "array.h"
 | 
|---|
| 22 | #include "timing.h"
 | 
|---|
| 23 | 
 | 
|---|
| 24 | using namespace std;
 | 
|---|
| 25 | 
 | 
|---|
| 26 | // ..........................................................
 | 
|---|
| 27 | // Programme interactive de test des threads ZThread
 | 
|---|
| 28 | // avec les arrays de Sophya et PI 
 | 
|---|
| 29 | //     R. Ansari  LAL-IN2P3/CNRS   02/2001
 | 
|---|
| 30 | // ..........................................................
 | 
|---|
| 31 | 
 | 
|---|
| 32 | // ................... MtxComputer ...................
 | 
|---|
| 33 | // A thread class for doing matrix computation 
 | 
|---|
| 34 | class PIZTApp;
 | 
|---|
| 35 | class MtxComputer : public ZThread   // <JThreadC++> 
 | 
|---|
| 36 | {
 | 
|---|
| 37 | public:
 | 
|---|
| 38 |   MtxComputer(PIZTApp * app, PIScale * sc, int id, int sz, int nloop);
 | 
|---|
| 39 |   virtual ~MtxComputer();
 | 
|---|
| 40 |   virtual void run();
 | 
|---|
| 41 | protected:
 | 
|---|
| 42 |   int id_;
 | 
|---|
| 43 |   int sz_;
 | 
|---|
| 44 |   int nloop_;
 | 
|---|
| 45 |   PIZTApp * zapp_;
 | 
|---|
| 46 |   PIScale * sc_;
 | 
|---|
| 47 | };
 | 
|---|
| 48 | 
 | 
|---|
| 49 | // ................... CPUTimer ...................
 | 
|---|
| 50 | // Periodic class for CPU and elapsed time counting 
 | 
|---|
| 51 | class CPUTimer : public PIPeriodic {
 | 
|---|
| 52 | public:
 | 
|---|
| 53 |   CPUTimer(PIZTApp * app);
 | 
|---|
| 54 |   virtual void DoPeriodic();
 | 
|---|
| 55 | protected:
 | 
|---|
| 56 |   PIZTApp * zapp; 
 | 
|---|
| 57 |   int dt;
 | 
|---|
| 58 | };
 | 
|---|
| 59 | 
 | 
|---|
| 60 | // ................... PIZTApp ...................
 | 
|---|
| 61 | // La classe application   <JThreadC++> 
 | 
|---|
| 62 | // class PIZTApp : public PIApplication , public ZThread {
 | 
|---|
| 63 | class PIZTApp : public PIApplication  {   // Pas oblige d'en faire un Thread
 | 
|---|
| 64 | public:
 | 
|---|
| 65 |   PIZTApp(int narg, char* arg[]);
 | 
|---|
| 66 |   ~PIZTApp();
 | 
|---|
| 67 |   virtual void   Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
 | 
|---|
| 68 |   virtual void   UpdateCPUTime();
 | 
|---|
| 69 |   virtual void   run();    //  <ZTread> 
 | 
|---|
| 70 |   // virtual void Run();    Si pas thread
 | 
|---|
| 71 |   ZMutex &   getMutex();  // <ZThread>  for synchronization 
 | 
|---|
| 72 | protected:
 | 
|---|
| 73 |   PIMenu * m[3];
 | 
|---|
| 74 |   PIScale *sc[2];
 | 
|---|
| 75 |   PILabel *tlab[2];
 | 
|---|
| 76 |   PILabel *cputlab;
 | 
|---|
| 77 |   PIConsole* cons;
 | 
|---|
| 78 |   // CPU and elapsed time
 | 
|---|
| 79 |   CPUTimer tm;
 | 
|---|
| 80 |   clock_t cput0;
 | 
|---|
| 81 |   time_t t0;
 | 
|---|
| 82 |   // The computing threads 
 | 
|---|
| 83 |   ZThread * thr[2];    //  <JThreadC++> 
 | 
|---|
| 84 |   // for synchronization with other threads
 | 
|---|
| 85 |   ZMutex amon;   //  <JThreadC++> 
 | 
|---|
| 86 |   int syn_cntrl;
 | 
|---|
| 87 | };
 | 
|---|
| 88 | 
 | 
|---|
| 89 | 
 | 
|---|
| 90 | // .........................................................
 | 
|---|
| 91 | // .............   PIZTApp  implementation .................
 | 
|---|
| 92 | // .........................................................
 | 
|---|
| 93 | 
 | 
|---|
| 94 | PIZTApp::PIZTApp(int narg, char* arg[])
 | 
|---|
| 95 |   : PIApplication(600, 400, narg, arg) , tm(this)  // 200 ms timer
 | 
|---|
| 96 | {
 | 
|---|
| 97 | if (narg < 3) throw ParmError("PIZTApp::PIZTApp() narg<3 !");
 | 
|---|
| 98 | 
 | 
|---|
| 99 | m[0] = new PIMenu(Menubar(),"Fichier");
 | 
|---|
| 100 | m[0]->AppendItem("Start", 10101);
 | 
|---|
| 101 | m[0]->AppendItem("Exit", 10110);
 | 
|---|
| 102 | AppendMenu(m[0]);
 | 
|---|
| 103 | m[1] = new PIMenu(Menubar(),"Thread-1");
 | 
|---|
| 104 | m[1]->AppendItem("Stop", 10203);
 | 
|---|
| 105 | AppendMenu(m[1]);
 | 
|---|
| 106 | m[2] = new PIMenu(Menubar(),"Thread-2");
 | 
|---|
| 107 | m[2]->AppendItem("Stop", 10303);
 | 
|---|
| 108 | AppendMenu(m[2]);
 | 
|---|
| 109 | 
 | 
|---|
| 110 | cputlab = new PILabel(MainWin(), "CPUTime", 590, 30, 5, 5);
 | 
|---|
| 111 | cputlab->SetBorderWidth(1);
 | 
|---|
| 112 | 
 | 
|---|
| 113 | tlab[0] = new PILabel(MainWin(), "Thr-1", 50, 30, 10, 40);
 | 
|---|
| 114 | sc[0] = new PIScale(MainWin(), "Sc-Thr-1", 510, kSDirLtoR, 220, 40, 70, 40);
 | 
|---|
| 115 | sc[0]->SetValue(0);
 | 
|---|
| 116 | tlab[1] = new PILabel(MainWin(), "Thr-2", 50, 30, 300, 40);
 | 
|---|
| 117 | sc[1] = new PIScale(MainWin(), "Sc-Thr-2", 520, kSDirLtoR, 220, 40, 360, 40);
 | 
|---|
| 118 | sc[1]->SetValue(0);
 | 
|---|
| 119 | 
 | 
|---|
| 120 | // Creating the console and redirecting output
 | 
|---|
| 121 | cons = new PIConsole(MainWin(), "PIConsole", 700, 500, 80, 600, 315, 0, 85, true );
 | 
|---|
| 122 | cons->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
 | 
|---|
| 123 | RedirectOutStream(cons);
 | 
|---|
| 124 | //RedirectErrStream(cons);
 | 
|---|
| 125 | 
 | 
|---|
| 126 | // Creating matrix Computing thread 
 | 
|---|
| 127 | int nloop = atoi(arg[1]);
 | 
|---|
| 128 | int size = atoi(arg[2]);
 | 
|---|
| 129 | thr[0] = new MtxComputer(this, sc[0], 0, size, nloop);
 | 
|---|
| 130 | thr[1] = new MtxComputer(this, sc[1], 1, size, nloop);
 | 
|---|
| 131 | 
 | 
|---|
| 132 | cput0 = clock();  t0 = time(NULL);
 | 
|---|
| 133 | tm.Start();  // We start our cpu timer
 | 
|---|
| 134 | syn_cntrl = 0;  // Normal event loop 
 | 
|---|
| 135 | }
 | 
|---|
| 136 | 
 | 
|---|
| 137 | PIZTApp::~PIZTApp()
 | 
|---|
| 138 | {
 | 
|---|
| 139 | cout << " Getting in PIZTApp::~PIZTApp() - " << endl;
 | 
|---|
| 140 | int k;
 | 
|---|
| 141 |  cout << " PIZTApp::~PIZTApp() - deleting m[0..2] ... " << endl;
 | 
|---|
| 142 | for(k=0; k<3; k++) delete m;
 | 
|---|
| 143 |  cout << " PIZTApp::~PIZTApp() - deleting tlab/sc[0..1] ... " << endl;
 | 
|---|
| 144 | for(k=0; k<2; k++) { delete tlab[k];  delete sc[k]; }
 | 
|---|
| 145 |  cout << " PIZTApp::~PIZTApp() - deleting cputlab ... " << endl;
 | 
|---|
| 146 | delete cputlab;
 | 
|---|
| 147 |  cout << " PIZTApp::~PIZTApp() - deleting thr[0..1] ... " << endl;
 | 
|---|
| 148 | delete thr[0];
 | 
|---|
| 149 | delete thr[1];
 | 
|---|
| 150 |  cout << " PIZTApp::~PIZTApp() - deleting cons ... " << endl;
 | 
|---|
| 151 | delete cons;
 | 
|---|
| 152 | }
 | 
|---|
| 153 | 
 | 
|---|
| 154 | void PIZTApp::UpdateCPUTime()
 | 
|---|
| 155 | {
 | 
|---|
| 156 | clock_t cput;
 | 
|---|
| 157 | time_t elt;
 | 
|---|
| 158 | time_t tm;  struct tm * stm;
 | 
|---|
| 159 | elt = time(&tm);  stm = localtime(&tm);
 | 
|---|
| 160 | cput = clock();
 | 
|---|
| 161 | float tcal = ( (float)(cput) - (float)(cput0) ) / (float)(CLOCKS_PER_SEC);
 | 
|---|
| 162 | float  etm = elt - t0;
 | 
|---|
| 163 | float percen = (elt > t0) ?  (tcal*100.)/etm : 0.;
 | 
|---|
| 164 | char buff[192];
 | 
|---|
| 165 | sprintf(buff, "%02d:%02d:%02d CPUTime= %g sec Elapsed= %g sec (%g %%)", 
 | 
|---|
| 166 |         stm->tm_hour, stm->tm_min, stm->tm_sec,
 | 
|---|
| 167 |         tcal, etm, percen);
 | 
|---|
| 168 | 
 | 
|---|
| 169 | string s = buff;
 | 
|---|
| 170 | cputlab->SetLabel(s);
 | 
|---|
| 171 | }
 | 
|---|
| 172 | 
 | 
|---|
| 173 | ZMutex &  PIZTApp::getMutex()
 | 
|---|
| 174 | {
 | 
|---|
| 175 | syn_cntrl++;
 | 
|---|
| 176 | return amon;
 | 
|---|
| 177 | }
 | 
|---|
| 178 | 
 | 
|---|
| 179 | void PIZTApp::run()
 | 
|---|
| 180 |   // void PIZTApp::Run()  Si pas thread
 | 
|---|
| 181 | {
 | 
|---|
| 182 | 
 | 
|---|
| 183 | XEvent evt;
 | 
|---|
| 184 | int szx, szy, szf;
 | 
|---|
| 185 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
 | 
|---|
| 186 | // Pour appeler FinishCreate() des objets dans la fenetre principale 
 | 
|---|
| 187 | if (mStop) { // C'est la premiere fois
 | 
|---|
| 188 |   topcont->SetSize(topcont->XSize(), topcont->YSize());
 | 
|---|
| 189 |   MBCont()->FinishCreate();   
 | 
|---|
| 190 |   }
 | 
|---|
| 191 | else mStop = true;   // On rerentre apres un stop 
 | 
|---|
| 192 | 
 | 
|---|
| 193 | cout << "DBG-PIZTApp::run/Run Starting event loop " << endl;
 | 
|---|
| 194 | try {
 | 
|---|
| 195 | 
 | 
|---|
| 196 |   while (mStop) {
 | 
|---|
| 197 |     //    while (syn_cntrl > 0) {
 | 
|---|
| 198 |     //      amon.wait();  //  <JThreadC++>  
 | 
|---|
| 199 |     //      syn_cntrl = 0;
 | 
|---|
| 200 |     //    }
 | 
|---|
| 201 |     while (XtAppPending(*appctx) != 0) {
 | 
|---|
| 202 |       amon.lock(); //  <ZThread> 
 | 
|---|
| 203 |       XtAppNextEvent(*appctx, &evt);
 | 
|---|
| 204 |       XtDispatchEvent(&evt);
 | 
|---|
| 205 |       amon.unlock(); // <ZThread>
 | 
|---|
| 206 |     }
 | 
|---|
| 207 |     //    usleep(1000);
 | 
|---|
| 208 |   }
 | 
|---|
| 209 | }
 | 
|---|
| 210 | catch (PThrowable  & e) {  
 | 
|---|
| 211 |   cerr << "PIZTApp::Run() Catched Exception  Msg= " << e.Msg() << endl;
 | 
|---|
| 212 | }
 | 
|---|
| 213 | catch (...) {
 | 
|---|
| 214 |   cerr << "PIZTApp::run() Catched ... exception " << endl;
 | 
|---|
| 215 | }
 | 
|---|
| 216 | 
 | 
|---|
| 217 | 
 | 
|---|
| 218 | }
 | 
|---|
| 219 | 
 | 
|---|
| 220 | void PIZTApp::Process(PIMessage msg, PIMsgHandler* sender, void* data)
 | 
|---|
| 221 | {
 | 
|---|
| 222 |   int num;
 | 
|---|
| 223 | try {
 | 
|---|
| 224 |   switch(UserMsg(msg)) {
 | 
|---|
| 225 |   case 10101 : // starting computing threads 
 | 
|---|
| 226 |     thr[0]->start();  //  <ZThread> 
 | 
|---|
| 227 |     thr[1]->start();  //  <ZThread> 
 | 
|---|
| 228 |     break;
 | 
|---|
| 229 |   case 10110 : // stoping computing threads 
 | 
|---|
| 230 |     RedirectOutStream(NULL);
 | 
|---|
| 231 |     RedirectErrStream(NULL);
 | 
|---|
| 232 |     cout << " PIZTApp::Process() Waiting for threads to terminate ... " << endl;
 | 
|---|
| 233 |     thr[0]->join();  //  <ZThread> 
 | 
|---|
| 234 |     thr[1]->join();  //  <ZThread> 
 | 
|---|
| 235 |     Stop();
 | 
|---|
| 236 |     break;
 | 
|---|
| 237 |   case 10203 :
 | 
|---|
| 238 |   case 10303 :
 | 
|---|
| 239 |     num = (UserMsg(msg)-10203)/100;
 | 
|---|
| 240 |     thr[num]->stop();  //  <ZThread> 
 | 
|---|
| 241 |     break;
 | 
|---|
| 242 |   }
 | 
|---|
| 243 | }
 | 
|---|
| 244 | catch (ZThreadExc  & e) {  // <ZThread>
 | 
|---|
| 245 |   cerr << "PIZTApp::Process() Catched ZThreadExc  Msg= " << e.Msg() << endl;
 | 
|---|
| 246 | }
 | 
|---|
| 247 | catch (...) {
 | 
|---|
| 248 |   cerr << "PIZTApp::Process() Catched ... exception " << endl;
 | 
|---|
| 249 | }
 | 
|---|
| 250 | 
 | 
|---|
| 251 | }
 | 
|---|
| 252 | 
 | 
|---|
| 253 | // .........................................................
 | 
|---|
| 254 | // .............   CPUTimer implementation .................
 | 
|---|
| 255 | // .........................................................
 | 
|---|
| 256 | 
 | 
|---|
| 257 | CPUTimer::CPUTimer(PIZTApp * app)
 | 
|---|
| 258 | : PIPeriodic(1)
 | 
|---|
| 259 | {
 | 
|---|
| 260 | zapp = app;
 | 
|---|
| 261 | dt = -1;
 | 
|---|
| 262 | SetIntervalms(200);  // 200 ms interval timer
 | 
|---|
| 263 | }
 | 
|---|
| 264 | 
 | 
|---|
| 265 | void
 | 
|---|
| 266 | CPUTimer::DoPeriodic()
 | 
|---|
| 267 | {
 | 
|---|
| 268 | dt++;
 | 
|---|
| 269 | if ((dt == 0) || (dt >= 5)) { zapp->UpdateCPUTime();  dt = 0; }
 | 
|---|
| 270 | }
 | 
|---|
| 271 | 
 | 
|---|
| 272 | 
 | 
|---|
| 273 | // .........................................................
 | 
|---|
| 274 | // .............  MtxComputer implementation ...............
 | 
|---|
| 275 | // .........................................................
 | 
|---|
| 276 | 
 | 
|---|
| 277 | // A global monitor for print synchronisation 
 | 
|---|
| 278 | ZMutex prtmon;  // <ZThread> 
 | 
|---|
| 279 | 
 | 
|---|
| 280 | MtxComputer::MtxComputer(PIZTApp * app, PIScale * sc, int id, int sz, int nloop)
 | 
|---|
| 281 | {
 | 
|---|
| 282 |   id_ = id;  sz_ = sz;  nloop_ = nloop;  zapp_ = app;  sc_ = sc; 
 | 
|---|
| 283 | }
 | 
|---|
| 284 | 
 | 
|---|
| 285 | MtxComputer::~MtxComputer()
 | 
|---|
| 286 | {
 | 
|---|
| 287 | }
 | 
|---|
| 288 | 
 | 
|---|
| 289 | void MtxComputer::run()
 | 
|---|
| 290 | {
 | 
|---|
| 291 |   int n = sz_;
 | 
|---|
| 292 |   double seuil = 1.e-6;
 | 
|---|
| 293 |   Matrix id;
 | 
|---|
| 294 |   id = IdentityMatrix(1.,n);
 | 
|---|
| 295 |   double gmax = -1.e99;
 | 
|---|
| 296 |   double gmin = 1.e99;
 | 
|---|
| 297 |   int npb = 0;
 | 
|---|
| 298 |   // Loop creating a random matrix, inverting it
 | 
|---|
| 299 |   // and checking the result 
 | 
|---|
| 300 |   for(int k=0; k<nloop_; k++) {
 | 
|---|
| 301 |     try {
 | 
|---|
| 302 |       Matrix a(n,n);
 | 
|---|
| 303 |       a = RandomSequence(RandomSequence::Gaussian, 0., 2.5);
 | 
|---|
| 304 |       Matrix inva = Inverse(a);
 | 
|---|
| 305 |       Matrix diff = id-a*inva;
 | 
|---|
| 306 |       double max = -1.e99;
 | 
|---|
| 307 |       double min = 1.e99;
 | 
|---|
| 308 |       double x;
 | 
|---|
| 309 |       int nerr = 0;
 | 
|---|
| 310 |       for(int i=0; i<n; i++) 
 | 
|---|
| 311 |         for(int j=0; j<n; j++) {
 | 
|---|
| 312 |           x = diff(i,j);
 | 
|---|
| 313 |           if (x < min)  min = diff(i,j); 
 | 
|---|
| 314 |           if (x > max)  max = diff(i,j); 
 | 
|---|
| 315 |           if (fabs(x) > seuil)  nerr++;
 | 
|---|
| 316 |         }
 | 
|---|
| 317 |       if (min < gmin) gmin = min;
 | 
|---|
| 318 |       if (max > gmax) gmax = max;
 | 
|---|
| 319 |       if (nerr > 0) npb++;
 | 
|---|
| 320 |       {  // Synchronized writing to cout stream  
 | 
|---|
| 321 |         ZSync sync(prtmon);  // <ZThread> 
 | 
|---|
| 322 |         cout << " ------- Thread[" << id_ << "] K= " 
 | 
|---|
| 323 |              << k << "  NErr = " << nerr << endl;
 | 
|---|
| 324 |         cout << "  Min(Diff) = " << min << " Max(Diff) = " << max << endl;
 | 
|---|
| 325 |         if (k == nloop_-1) {
 | 
|---|
| 326 |           double frac = (double)npb*100./(double)nloop_;
 | 
|---|
| 327 |           cout << " ...... Thread[" << id_ << "] End NPb= " << npb 
 | 
|---|
| 328 |                << " / NTot= " << nloop_ << " ( = " << frac << " %) " << endl;
 | 
|---|
| 329 |           cout << "  GMin(Diff) = " << gmin << " GMax(Diff) = " << gmax << endl;
 | 
|---|
| 330 |           cout << " ..................................................... " << endl;
 | 
|---|
| 331 |         }
 | 
|---|
| 332 |       }
 | 
|---|
| 333 |       {  // Synchronized updating of Scale Widget 
 | 
|---|
| 334 |         ZSync sync(zapp_->getMutex());  // <ZThread> 
 | 
|---|
| 335 |         // The event loop should be stopped until the end of the block
 | 
|---|
| 336 |         int percentage = 100*(k+1)/nloop_;
 | 
|---|
| 337 |         sc_->SetValue(percentage);
 | 
|---|
| 338 |       }
 | 
|---|
| 339 |  
 | 
|---|
| 340 |     }
 | 
|---|
| 341 |     catch (ZThreadExc const & e) {  // <ZThread>
 | 
|---|
| 342 |       cerr << "MtxComputer Catched ZThreadExc in  Thread(" // << (string)getName() 
 | 
|---|
| 343 |              << ") Msg= " << e.Msg() << endl;
 | 
|---|
| 344 |     }
 | 
|---|
| 345 |     catch (PException const & e) {
 | 
|---|
| 346 |       cerr << "MtxComputer Catched PException in  Thread(" // << (string)getName() 
 | 
|---|
| 347 |              << ") Msg= " << e.Msg() << endl;
 | 
|---|
| 348 |     }
 | 
|---|
| 349 |   }
 | 
|---|
| 350 | }
 | 
|---|
| 351 | 
 | 
|---|
| 352 | 
 | 
|---|
| 353 | static void run_piapp(void * x)
 | 
|---|
| 354 | {
 | 
|---|
| 355 |     PIZTApp * t = (PIZTApp *)x;
 | 
|---|
| 356 |     t->run();
 | 
|---|
| 357 |     return;
 | 
|---|
| 358 | }
 | 
|---|
| 359 | 
 | 
|---|
| 360 | // .........................................................
 | 
|---|
| 361 | // ................... The main program ....................
 | 
|---|
| 362 | // .........................................................
 | 
|---|
| 363 | 
 | 
|---|
| 364 | int main(int narg, char* arg[])
 | 
|---|
| 365 | {
 | 
|---|
| 366 | 
 | 
|---|
| 367 |   if (narg < 3) {
 | 
|---|
| 368 |     cout << " pizthr - ZThread/PI/Sophya::TArray<T> Test \n " 
 | 
|---|
| 369 |          << " ... Usage pizthr NLoop MtxSize [-JTCss ... \n" 
 | 
|---|
| 370 |          << "     NLoop=10...10^4  MtxSize=10...10^3 \n"
 | 
|---|
| 371 |          << endl;
 | 
|---|
| 372 |     exit(0);
 | 
|---|
| 373 |   }
 | 
|---|
| 374 | 
 | 
|---|
| 375 |   InitTim();   // Initializing the CPU timer
 | 
|---|
| 376 | 
 | 
|---|
| 377 |   int nloop = atoi(arg[1]);
 | 
|---|
| 378 |   int size = atoi(arg[2]);
 | 
|---|
| 379 |   cout << " ::::: pizthr - ZThread/PI/Sophya::TArray<T> Test ::::: \n"
 | 
|---|
| 380 |        << " NLoop= " << nloop << " MtxSize= " << size << endl;   
 | 
|---|
| 381 | 
 | 
|---|
| 382 |   try {
 | 
|---|
| 383 |     SophyaInit();  // Sophya Initialization
 | 
|---|
| 384 |     PIZTApp * t = new PIZTApp(narg, arg);  // <ZThread>  
 | 
|---|
| 385 |     //    t->Run();
 | 
|---|
| 386 |     ZThread * zt = new ZThread(50000);
 | 
|---|
| 387 |     zt->setAction(run_piapp, t);
 | 
|---|
| 388 |     zt->start();   // <ZThread>  -   starting event loop 
 | 
|---|
| 389 |     cout << " Waiting for PIZTApp thread to end ... " << endl;
 | 
|---|
| 390 |     zt->join();    // <ZThread>  Waiting for thread to end
 | 
|---|
| 391 |     //  PIZTApp * t = new  PIZTApp(narg, arg); Si pas thread
 | 
|---|
| 392 |     //  t->Run();      Si pas thread
 | 
|---|
| 393 |     cout << " PIZTApp thread ended - deleting PIZTApplication ... " << endl;
 | 
|---|
| 394 |     delete zt;
 | 
|---|
| 395 |     delete t;
 | 
|---|
| 396 |   }
 | 
|---|
| 397 |   catch (PThrowable const & e) {
 | 
|---|
| 398 |     cerr << " Catched PThrowable in main Msg= " << e.Msg() << endl;
 | 
|---|
| 399 |   }
 | 
|---|
| 400 |   catch(...) {
 | 
|---|
| 401 |     cerr << " Catched ... exception in main " << endl;
 | 
|---|
| 402 |   }
 | 
|---|
| 403 | 
 | 
|---|
| 404 |   PrtTim("End of pizthr");
 | 
|---|
| 405 | }
 | 
|---|
| 406 | 
 | 
|---|
| 407 | 
 | 
|---|
| 408 | 
 | 
|---|
| 409 | 
 | 
|---|