static void *
worker (void *)
{
  for (int iterations = 1;
       iterations <= n_iterations;
       iterations++)
    {
#if !defined (ACE_HAS_STHREADS) && !defined (ACE_HAS_POSIX_SEM)
      ACE_Time_Value wait (0,
                           iterations * 1000 * 100);  // Wait 'iter' msec
      ACE_Time_Value tv = ACE_OS::gettimeofday () + wait;

      if (s.acquire (tv))
        ++timeouts;
      else
        {
          ACE_Time_Value diff = ACE_OS::gettimeofday ();
          diff = diff - tv;       // tv should have been reset to time acquired
          if (diff.msec () > ACE_ALLOWED_SLACK)
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("Acquire fails time reset test\n")));
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("Diff btw now and returned time: %d ms\n"),
                          diff.msec ()));
              test_result = 1;
            }
          // Hold the lock for a while.
          ACE_OS::sleep (ACE_Time_Value (0,
                                         (ACE_OS::rand () % 1000) * 1000));
          s.release ();
        }
#else
      s.acquire ();
      // Hold the lock for a while.
      ACE_OS::sleep (ACE_Time_Value (0,
                                     (ACE_OS::rand () % 1000) * 1000));
      s.release ();
#endif /* ACE_HAS_STHREADS && ACE_HAS_POSIX_SEM */
      ACE_Thread::yield ();
    }

  return 0;
}
Exemple #2
0
// Tests the amount of time spent in a timed wait.
static int
test_timeout (void)
{
  int status = 0;

  // milliseconds...
  long msecs_expected;
  long msecs_waited;
  long msecs_diff;

  // Wait a little longer each time
  static long wait_secs = 3;

  ACE_Time_Value wait = ACE_OS::gettimeofday ();

  ACE_Time_Value begin = wait;

  wait.sec (wait.sec () + wait_secs);

  if (s.acquire (wait) == -1)
    {
      if (errno != ETIME)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("test_timeout should be ETIME but is")));
          status = -1;
        }
    }

  ACE_Time_Value wait_diff = ACE_OS::gettimeofday () - begin;

  msecs_waited = wait_diff.msec ();
  msecs_expected = wait_secs * 1000;
  msecs_diff = labs (msecs_expected - msecs_waited);

  if (msecs_diff > ACE_ALLOWED_SLACK)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Timed wait fails length test\n")));
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Expected %d ms, actual %d ms; %d allowed\n"),
                  (int)msecs_expected,
                  (int)msecs_waited,
                  (int)ACE_ALLOWED_SLACK));
      status = -1;
    }

  ++wait_secs;
  return status;
}
Exemple #3
0
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 (s.acquire (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));
          s.release ();
        }
      ACE_Thread::yield ();
    }

  return 0;
}
// Tests the amount of time spent in a timed wait.
static int
test_timeout (void)
{
  int status = 0;

  // milliseconds...
  long msecs_expected;
  long msecs_waited;
  long msecs_diff;

  // Wait a little longer each time
  static long wait_secs = 3;

  ACE_Time_Value wait = ACE_OS::gettimeofday ();

  ACE_Time_Value begin = wait;

  wait.sec (wait.sec () + wait_secs);

  if (s.acquire (wait) == -1)
    ACE_ASSERT (errno == ETIME);

  ACE_Time_Value wait_diff = ACE_OS::gettimeofday () - begin;

  msecs_waited = wait_diff.msec ();
  msecs_expected = wait_secs * 1000;
  msecs_diff = labs (msecs_expected - msecs_waited);

  if (msecs_diff > ACE_ALLOWED_SLACK)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Timed wait fails length test\n")));
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Value: %d ms, actual %d ms\n"),
                  msecs_expected,
                  msecs_waited));
      status = -1;
    }

  ++wait_secs;
  return status;
}
int
MyTask::start (int num_threads)
{
  if (this->create_reactor () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p.\n"),
                       ACE_TEXT ("unable to create reactor")),
                      -1);

  if (this->activate (THR_NEW_LWP, num_threads) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p.\n"),
                       ACE_TEXT ("unable to activate thread pool")),
                      -1);

  for (; num_threads > 0 ; num_threads--)
    sem_.acquire ();

  return 0;
}