Ejemplo n.º 1
0
/* This is one of our accountants.  */
static THREAD_RET_TYPE
accountant_thread (void *arg)
{
  gpg_err_code_t rc;
  int i;
  int acc1, acc2;
  int value;

  (void)arg;

#ifdef _WIN32
  srand (time(NULL)*getpid());  /* Windows needs it per thread.  */
#endif
  for (i = 0; i < N_TRANSACTIONS; i++)
    {
      rc = gpgrt_lock_lock (&accounts_lock);
      if (rc)
        fail ("gpgrt_lock_lock failed at %d: %s", __LINE__, gpg_strerror (rc));

      acc1 = pick_account ();
      acc2 = pick_account ();
      value = pick_value ();
      account[acc1] += value;
      account[acc2] -= value;

      rc = gpgrt_lock_unlock (&accounts_lock);
      if (rc)
        fail ("gpgrt_lock_unlock failed at %d: %s", __LINE__,gpg_strerror (rc));
      if (i && !(i%8))
        gpgrt_yield ();
    }
  return THREAD_RET_VALUE;
}
Ejemplo n.º 2
0
/* This is one of our accountants.  */
static THREAD_RET_TYPE
accountant_thread (void *arg)
{
  int i;
  int acc1, acc2;
  int value;

  (void)arg;

  for (i = 0; i < N_TRANSACTIONS; i++)
    {
      external_lock_test_lock (__LINE__);
      acc1 = pick_account ();
      acc2 = pick_account ();
      value = pick_value ();
      account[acc1] += value;
      account[acc2] -= value;
      external_lock_test_unlock (__LINE__);
    }
  return THREAD_RET_VALUE;
}