int main()
{
#ifdef __MSVC_DEBUG__
  InitLeakTest();
#endif

  const unsigned NUM_WORKERS = 10;

  SimpleThread *t = new SimpleThread;
  thrPool *pool = new thrPool;

  unsigned i;
  for(i = 0; i < NUM_WORKERS; i++) {
    t->CreateThread(pool, (void *)i);
    t->sSleep(1);
  }

  t->JoinThread(pool);

  cout << "\n" << flush;
  cout << "Destroying the thread pool..." << "\n" << flush;
  t->DestroyThreadPool(pool);

  cout << "Creating anther pool of " << NUM_WORKERS << " threads" 
       << "\n" << flush;
  PausePrg();

  display_message = 0; // Do not display any console messages
  pool = t->CreateThreadPool(NUM_WORKERS);

  t->sSleep(1);
  cout << "\n" << flush;
  cout << "Rebuilding the pool" << "\n" << flush;
  t->RebuildThreadPool(pool);

  // Wait for the treads to finish before destroying the pool
  t->JoinThread(pool);

  cout << "\n" << flush;
  cout << "Destroying the thread pool..." << "\n" << flush;
  if(!pool->IsEmpty()) {
    t->DestroyThreadPool(pool);
  }
  else {
    cout << "The pool is empty" << "\n" << flush;
    // If DestroyThreadPool() is not called the pool will not be deleted
    delete pool; 
  }
  
  cout << "Exiting..." << "\n" << flush;
  delete t;

  return 0; // Exit the process, terminating all threads
}
Beispiel #2
0
// Main thread of execution
int main()
{
#ifdef __MSVC_DEBUG__
  InitLeakTest();
#endif

  SimpleThread t;

  const int num_threads = 10;
  gxThread_t *thread[num_threads];

  int i;
  for(i = 0; i < num_threads; i++) {
    thread[i] = t.CreateThread();
    t.sSleep(1);
  }

  // Wait for all the threads to finish before exiting
  for(i = 0; i < num_threads; ++i) {
    if(t.JoinThread(thread[i]) != 0)
      cout << "Could not join the thread" << "\n";
    if(thread[i]->GetThreadExitCode() != THREAD_EXIT_CODE)
      cout << "This thread exited with an error" << "\n";
  }

  // Prevent memory leaks
  for(i = 0; i < num_threads; ++i) delete thread[i];
  
  return 0; // Exit the process
}
int main()
{
#ifdef __MSVC_DEBUG__
  InitLeakTest();
#endif

  SimpleThread t;
  char *message1 = "Test message 1";
  char *message2 = "Test message 2";

  t.message = message1;
  gxThread_t *thread = t.CreateThread();

  t.sSleep(1); // Wait for the first thread to exit
  delete thread; // Prevent memory leak
  
  t.message = message2;
  thread = t.CreateThread();
  t.sSleep(1); // Wait for the second thread to exit
  delete thread;

  cout << "\n" << flush;
  cout << "Testing all the reentrant gxThread sleep functions..."
       << "\n" << flush;

  cout << "Sleeping for 1 second" << "\n" << flush;
  t.sSleep(1);

  cout << "Sleeping for 1000 milliseconds" << "\n" << flush;
  t.mSleep(1000);

  cout << "Sleeping for 1000000 microseconds" << "\n" << flush;
  t.uSleep(1000000);

  cout << "Sleeping for 100 microseconds" << "\n" << flush;
  t.uSleep(100);

  cout << "Sleeping for 1000000000 nanoseconds" << "\n" << flush;
  t.nSleep(1000000000);

  cout << "Sleeping for 100 nanoseconds" << "\n" << flush;
  t.nSleep(100);

  return 0; // Exit the process
}
int main()
{
#ifdef __MSVC_DEBUG__
  InitLeakTest();
#endif

  SimpleThread t;
  char *message1 = "The quick brown fox jumps over the lazy dog";

  // Test the parameter passing to create function
  gxThread_t *tptr = t.CreateThread((void *)message1);

  // Wait for the thread to exit
  t.sSleep(1); 

  delete tptr; // Prevent memory leaks
  return 0; // Exit the process
}