コード例 #1
0
ファイル: Auto_Event_Test.cpp プロジェクト: chrrrisw/ACE
static void *
worker (void *)
{
  for (int iterations = 1;
       iterations <= n_iterations;
       iterations++)
    {
      //FUZZ: disable check_for_lack_ACE_OS
      ACE_Time_Value wait (0,
                           iterations * 1000 * 100);  // Wait 'iter' msec
      //FUZZ: enable check_for_lack_ACE_OS

      ACE_Time_Value tv = ACE_OS::gettimeofday () + wait;
      if (evt.wait (&tv) == -1)
      {
          // verify that we have ETIME
          if (ACE_OS::last_error() != ETIME)
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("%p\n"),
                          ACE_TEXT ("Worker should be ETIME but is")));
            }
          else
            ++timeouts;
          ACE_Time_Value diff = ACE_OS::gettimeofday ();
          diff = diff - tv;       // tv should have been reset to time acquired
          long diff_msec = diff.msec ();

          if (diff_msec > ACE_ALLOWED_SLACK)
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Acquire fails time reset test\n")));
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Diff btw now and returned time: %d ms; ")
                          ACE_TEXT ("%d allowed\n"),
                          (int)diff_msec,
                          (int)ACE_ALLOWED_SLACK));
              test_result = 1;
            }
          // Hold the lock for a while.
          ACE_OS::sleep (ACE_Time_Value (0,
                                         (ACE_OS::rand () % 1000) * 1000));
          evt.signal ();
      }

      ACE_Thread::yield ();
    }

  return 0;
}
コード例 #2
0
ファイル: Auto_Event_Test.cpp プロジェクト: chrrrisw/ACE
int run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Auto_Event_Test"));

#if defined (ACE_HAS_THREADS)
  parse_args (argc, argv);
  ACE_OS::srand ((u_int) ACE_OS::time (0L));

  //Test timed waits.
  for (size_t i = 0; i < test_timeout_count; i++)
    if (test_timeout () != 0)
      test_result = 1;

  if (ACE_Thread_Manager::instance ()->spawn_n
      (static_cast<size_t> (n_workers),
       ACE_THR_FUNC (worker),
       0,
       THR_NEW_LWP) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("spawn_n")),
                      1);

  // Release the first worker.
  evt.signal ();

  ACE_Thread_Manager::instance ()->wait ();

  size_t percent = (timeouts * 100) / (n_workers * n_iterations);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Worker threads timed out %d percent of the time\n"),
              (int)percent));

  if (test_result == 0)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Auto_Event Test successful\n")));
#else
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
  ACE_ERROR ((LM_INFO,
              ACE_TEXT ("Threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
  ACE_END_TEST;
  return test_result;
}