reSIProcate/rutil  9694
Classes | Functions
testThreadIf.cxx File Reference
#include "rutil/ThreadIf.hxx"
#include "rutil/Timer.hxx"
#include <unistd.h>
#include <iostream>
#include <vector>
#include <cassert>
Include dependency graph for testThreadIf.cxx:

Go to the source code of this file.

Classes

class  Every4
class  Old2
class  ShutdownSelf
class  DerivedShutsDown

Functions

int main ()

Function Documentation

int main ( void  )

Definition at line 77 of file testThreadIf.cxx.

References resip::Timer::getTimeMs(), resip::ThreadIf::join(), resip::ThreadIf::run(), and resip::ThreadIf::shutdown().

{
   {
      DerivedShutsDown d;
   }
      
   {
      vector<DerivedShutsDown*> threads;
      int numThreads = 20;
      
      for (int i=0; i < numThreads; i++)
      {
         threads.push_back(new DerivedShutsDown);
         threads.back()->run();
      }
      sleep(1);
      for (int i=0; i < numThreads; i++)
      {
         delete threads[i];
      }
      cerr << "finished many-thread test" << endl;
   }
   
   {
      DerivedShutsDown d;
      d.run();
      usleep(10000);
   }
   {
      ShutdownSelf* s= new ShutdownSelf();
      s->run();
      usleep(10000);
      s->shutdown();
      delete s;
   }
   {
        Every4 e;
        e.run();
        sleep(5);
        UInt64 t = Timer::getTimeMs();
        cerr << "Stopping thread at: " << Timer::getTimeMs() << endl;
        e.shutdown();
        e.join();
        UInt64 j = Timer::getTimeMs();
        cerr << j - t << endl;
        
        assert(j - t < 20);
    }
    //this should not cause problems(signal is being called on a condition with
    //no waiting threads).
    {
        Old2 o;
        o.run();
        sleep(3);
        o.shutdown();
        o.join();
    }
    cerr << "OK" << endl;
    return 0;
}

Here is the call graph for this function: