mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2025-08-08 17:22:05 +03:00
tests: In multithreaded tests, use random() instead of rand().
* tests/test-asyncsafe-spin2.c (random_account, lock_mutator_thread): Use random() instead of rand(). * tests/test-lock.c (random_account, lock_mutator_thread, rwlock_mutator_thread, recshuffle): Likewise. * tests/test-mtx.c (random_account, lock_mutator_thread, recshuffle): Likewise. * tests/test-pthread-mutex.c (random_account, lock_mutator_thread, recshuffle): Likewise. * tests/test-pthread-rwlock.c (random_account, rwlock_mutator_thread): Likewise. * tests/test-pthread-spin.c (random_account, lock_mutator_thread): Likewise. * tests/test-pthread-tss.c (perhaps_yield, worker_thread, racecheck_thread): Likewise. * tests/test-thread_local.c (perhaps_yield, worker_thread): Likewise. * tests/test-tls.c (perhaps_yield, worker_thread, racecheck_thread): Likewise. * tests/test-tss.c (perhaps_yield, worker_thread, racecheck_thread): Likewise. * asyncsafe-spin-tests (Depends-on): Add random. * lock-tests (Depends-on): Likewise. * mtx-tests (Depends-on): Likewise. * pthread-mutex-tests (Depends-on): Likewise. * pthread-rwlock-tests (Depends-on): Likewise. * pthread-spin-tests (Depends-on): Likewise. * pthread-tss-tests (Depends-on): Likewise. * threads-h-tests (Depends-on): Likewise. * tls-tests (Depends-on): Likewise. * tss-tests (Depends-on): Likewise.
This commit is contained in:
33
ChangeLog
33
ChangeLog
@@ -1,3 +1,36 @@
|
|||||||
|
2023-11-10 Bruno Haible <bruno@clisp.org>
|
||||||
|
|
||||||
|
tests: In multithreaded tests, use random() instead of rand().
|
||||||
|
* tests/test-asyncsafe-spin2.c (random_account, lock_mutator_thread):
|
||||||
|
Use random() instead of rand().
|
||||||
|
* tests/test-lock.c (random_account, lock_mutator_thread,
|
||||||
|
rwlock_mutator_thread, recshuffle): Likewise.
|
||||||
|
* tests/test-mtx.c (random_account, lock_mutator_thread, recshuffle):
|
||||||
|
Likewise.
|
||||||
|
* tests/test-pthread-mutex.c (random_account, lock_mutator_thread,
|
||||||
|
recshuffle): Likewise.
|
||||||
|
* tests/test-pthread-rwlock.c (random_account, rwlock_mutator_thread):
|
||||||
|
Likewise.
|
||||||
|
* tests/test-pthread-spin.c (random_account, lock_mutator_thread):
|
||||||
|
Likewise.
|
||||||
|
* tests/test-pthread-tss.c (perhaps_yield, worker_thread,
|
||||||
|
racecheck_thread): Likewise.
|
||||||
|
* tests/test-thread_local.c (perhaps_yield, worker_thread): Likewise.
|
||||||
|
* tests/test-tls.c (perhaps_yield, worker_thread, racecheck_thread):
|
||||||
|
Likewise.
|
||||||
|
* tests/test-tss.c (perhaps_yield, worker_thread, racecheck_thread):
|
||||||
|
Likewise.
|
||||||
|
* asyncsafe-spin-tests (Depends-on): Add random.
|
||||||
|
* lock-tests (Depends-on): Likewise.
|
||||||
|
* mtx-tests (Depends-on): Likewise.
|
||||||
|
* pthread-mutex-tests (Depends-on): Likewise.
|
||||||
|
* pthread-rwlock-tests (Depends-on): Likewise.
|
||||||
|
* pthread-spin-tests (Depends-on): Likewise.
|
||||||
|
* pthread-tss-tests (Depends-on): Likewise.
|
||||||
|
* threads-h-tests (Depends-on): Likewise.
|
||||||
|
* tls-tests (Depends-on): Likewise.
|
||||||
|
* tss-tests (Depends-on): Likewise.
|
||||||
|
|
||||||
2023-11-10 Bruno Haible <bruno@clisp.org>
|
2023-11-10 Bruno Haible <bruno@clisp.org>
|
||||||
|
|
||||||
doc: Mention an srandom limitation on OpenBSD.
|
doc: Mention an srandom limitation on OpenBSD.
|
||||||
|
@@ -8,6 +8,7 @@ Depends-on:
|
|||||||
thread
|
thread
|
||||||
lock
|
lock
|
||||||
yield
|
yield
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
AC_CHECK_HEADERS_ONCE([semaphore.h])
|
AC_CHECK_HEADERS_ONCE([semaphore.h])
|
||||||
|
@@ -11,6 +11,7 @@ thread
|
|||||||
stdint
|
stdint
|
||||||
usleep
|
usleep
|
||||||
yield
|
yield
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
AC_CHECK_HEADERS_ONCE([semaphore.h])
|
AC_CHECK_HEADERS_ONCE([semaphore.h])
|
||||||
|
@@ -7,6 +7,7 @@ Depends-on:
|
|||||||
thrd
|
thrd
|
||||||
lock
|
lock
|
||||||
stdint
|
stdint
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
AC_CHECK_HEADERS_ONCE([semaphore.h])
|
AC_CHECK_HEADERS_ONCE([semaphore.h])
|
||||||
|
@@ -6,6 +6,7 @@ tests/macros.h
|
|||||||
Depends-on:
|
Depends-on:
|
||||||
pthread-thread
|
pthread-thread
|
||||||
sched_yield
|
sched_yield
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ Depends-on:
|
|||||||
pthread-thread
|
pthread-thread
|
||||||
pthread-mutex
|
pthread-mutex
|
||||||
sched_yield
|
sched_yield
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ Depends-on:
|
|||||||
pthread-thread
|
pthread-thread
|
||||||
pthread-mutex
|
pthread-mutex
|
||||||
sched_yield
|
sched_yield
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
AC_CHECK_HEADERS_ONCE([semaphore.h])
|
AC_CHECK_HEADERS_ONCE([semaphore.h])
|
||||||
|
@@ -6,6 +6,7 @@ Depends-on:
|
|||||||
pthread-thread
|
pthread-thread
|
||||||
pthread-mutex
|
pthread-mutex
|
||||||
sched_yield
|
sched_yield
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ Depends-on:
|
|||||||
threads-h-c++-tests
|
threads-h-c++-tests
|
||||||
thrd
|
thrd
|
||||||
stdint
|
stdint
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
AC_CHECK_DECLS_ONCE([alarm])
|
AC_CHECK_DECLS_ONCE([alarm])
|
||||||
|
@@ -6,6 +6,7 @@ thread
|
|||||||
lock
|
lock
|
||||||
stdint
|
stdint
|
||||||
yield
|
yield
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
AC_CHECK_DECLS_ONCE([alarm])
|
AC_CHECK_DECLS_ONCE([alarm])
|
||||||
|
@@ -6,6 +6,7 @@ Depends-on:
|
|||||||
thrd
|
thrd
|
||||||
mtx
|
mtx
|
||||||
stdint
|
stdint
|
||||||
|
random
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
AC_CHECK_DECLS_ONCE([alarm])
|
AC_CHECK_DECLS_ONCE([alarm])
|
||||||
|
@@ -95,7 +95,7 @@ static int account[ACCOUNT_COUNT];
|
|||||||
static int
|
static int
|
||||||
random_account (void)
|
random_account (void)
|
||||||
{
|
{
|
||||||
return ((unsigned int) rand () >> 3) % ACCOUNT_COUNT;
|
return ((unsigned long) random () >> 3) % ACCOUNT_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -135,7 +135,7 @@ lock_mutator_thread (void *arg)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
|
@@ -118,7 +118,7 @@ static int account[ACCOUNT_COUNT];
|
|||||||
static int
|
static int
|
||||||
random_account (void)
|
random_account (void)
|
||||||
{
|
{
|
||||||
return ((unsigned int) rand () >> 3) % ACCOUNT_COUNT;
|
return ((unsigned long) random () >> 3) % ACCOUNT_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -157,7 +157,7 @@ lock_mutator_thread (_GL_UNUSED void *arg)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ rwlock_mutator_thread (_GL_UNUSED void *arg)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
@@ -331,12 +331,12 @@ recshuffle (void)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
/* Recursive with probability 0.5. */
|
/* Recursive with probability 0.5. */
|
||||||
if (((unsigned int) rand () >> 3) % 2)
|
if (((unsigned long) random () >> 3) % 2)
|
||||||
recshuffle ();
|
recshuffle ();
|
||||||
|
|
||||||
dbgprintf ("Mutator %p before unlock\n", gl_thread_self_pointer ());
|
dbgprintf ("Mutator %p before unlock\n", gl_thread_self_pointer ());
|
||||||
|
@@ -92,7 +92,7 @@ static int account[ACCOUNT_COUNT];
|
|||||||
static int
|
static int
|
||||||
random_account (void)
|
random_account (void)
|
||||||
{
|
{
|
||||||
return ((unsigned int) rand () >> 3) % ACCOUNT_COUNT;
|
return ((unsigned long) random () >> 3) % ACCOUNT_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -131,7 +131,7 @@ lock_mutator_thread (void *arg)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
@@ -220,12 +220,12 @@ recshuffle (void)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
/* Recursive with probability 0.5. */
|
/* Recursive with probability 0.5. */
|
||||||
if (((unsigned int) rand () >> 3) % 2)
|
if (((unsigned long) random () >> 3) % 2)
|
||||||
recshuffle ();
|
recshuffle ();
|
||||||
|
|
||||||
dbgprintf ("Mutator %p before unlock\n", thrd_current_pointer ());
|
dbgprintf ("Mutator %p before unlock\n", thrd_current_pointer ());
|
||||||
|
@@ -93,7 +93,7 @@ static int account[ACCOUNT_COUNT];
|
|||||||
static int
|
static int
|
||||||
random_account (void)
|
random_account (void)
|
||||||
{
|
{
|
||||||
return ((unsigned int) rand () >> 3) % ACCOUNT_COUNT;
|
return ((unsigned long) random () >> 3) % ACCOUNT_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -132,7 +132,7 @@ lock_mutator_thread (void *arg)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
@@ -220,12 +220,12 @@ recshuffle (void)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
/* Recursive with probability 0.5. */
|
/* Recursive with probability 0.5. */
|
||||||
if (((unsigned int) rand () >> 3) % 2)
|
if (((unsigned long) random () >> 3) % 2)
|
||||||
recshuffle ();
|
recshuffle ();
|
||||||
|
|
||||||
dbgprintf ("Mutator %p before unlock\n", pthread_self_pointer ());
|
dbgprintf ("Mutator %p before unlock\n", pthread_self_pointer ());
|
||||||
|
@@ -87,7 +87,7 @@ static int account[ACCOUNT_COUNT];
|
|||||||
static int
|
static int
|
||||||
random_account (void)
|
random_account (void)
|
||||||
{
|
{
|
||||||
return ((unsigned int) rand () >> 3) % ACCOUNT_COUNT;
|
return ((unsigned long) random () >> 3) % ACCOUNT_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -126,7 +126,7 @@ rwlock_mutator_thread (void *arg)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
|
@@ -85,7 +85,7 @@ static int account[ACCOUNT_COUNT];
|
|||||||
static int
|
static int
|
||||||
random_account (void)
|
random_account (void)
|
||||||
{
|
{
|
||||||
return ((unsigned int) rand () >> 3) % ACCOUNT_COUNT;
|
return ((unsigned long) random () >> 3) % ACCOUNT_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -124,7 +124,7 @@ lock_mutator_thread (void *arg)
|
|||||||
|
|
||||||
i1 = random_account ();
|
i1 = random_account ();
|
||||||
i2 = random_account ();
|
i2 = random_account ();
|
||||||
value = ((unsigned int) rand () >> 3) % 10;
|
value = ((unsigned long) random () >> 3) % 10;
|
||||||
account[i1] += value;
|
account[i1] += value;
|
||||||
account[i2] -= value;
|
account[i2] -= value;
|
||||||
|
|
||||||
|
@@ -71,7 +71,7 @@ perhaps_yield (void)
|
|||||||
{
|
{
|
||||||
/* Call yield () only with a certain probability, otherwise the
|
/* Call yield () only with a certain probability, otherwise the
|
||||||
sequence of thread activations may be too predictable. */
|
sequence of thread activations may be too predictable. */
|
||||||
if ((((unsigned int) rand () >> 3) % 4) == 0)
|
if ((((unsigned long) random () >> 3) % 4) == 0)
|
||||||
yield ();
|
yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ worker_thread (void *arg)
|
|||||||
/* Initialize the per-thread storage. */
|
/* Initialize the per-thread storage. */
|
||||||
for (i = 0; i < KEYS_COUNT; i++)
|
for (i = 0; i < KEYS_COUNT; i++)
|
||||||
{
|
{
|
||||||
values[i] = (((unsigned int) rand () >> 3) % 1000000) * THREAD_COUNT + id;
|
values[i] = (((unsigned long) random () >> 3) % 1000000) * THREAD_COUNT + id;
|
||||||
/* Hopefully no arithmetic overflow. */
|
/* Hopefully no arithmetic overflow. */
|
||||||
if ((values[i] % THREAD_COUNT) != id)
|
if ((values[i] % THREAD_COUNT) != id)
|
||||||
abort ();
|
abort ();
|
||||||
@@ -132,8 +132,8 @@ worker_thread (void *arg)
|
|||||||
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
||||||
{
|
{
|
||||||
dbgprintf ("Worker %p doing value swapping\n", pthread_self_pointer ());
|
dbgprintf ("Worker %p doing value swapping\n", pthread_self_pointer ());
|
||||||
i = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
i = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
j = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
j = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
if (i != j)
|
if (i != j)
|
||||||
{
|
{
|
||||||
void *vi = pthread_getspecific (mykeys[i]);
|
void *vi = pthread_getspecific (mykeys[i]);
|
||||||
@@ -462,7 +462,7 @@ racecheck_thread (void *arg)
|
|||||||
|
|
||||||
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
||||||
{
|
{
|
||||||
i = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
i = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
dbgprintf ("Worker %p reallocating key %d\n", pthread_self_pointer (), i);
|
dbgprintf ("Worker %p reallocating key %d\n", pthread_self_pointer (), i);
|
||||||
ASSERT (pthread_key_delete (keys[i]) == 0);
|
ASSERT (pthread_key_delete (keys[i]) == 0);
|
||||||
ASSERT (pthread_key_create (&keys[i], destructor_table[i]) == 0);
|
ASSERT (pthread_key_create (&keys[i], destructor_table[i]) == 0);
|
||||||
|
@@ -76,7 +76,7 @@ perhaps_yield (void)
|
|||||||
{
|
{
|
||||||
/* Call yield () only with a certain probability, otherwise the
|
/* Call yield () only with a certain probability, otherwise the
|
||||||
sequence of thread activations may be too predictable. */
|
sequence of thread activations may be too predictable. */
|
||||||
if ((((unsigned int) rand () >> 3) % 4) == 0)
|
if ((((unsigned long) random () >> 3) % 4) == 0)
|
||||||
yield ();
|
yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ worker_thread (void *arg)
|
|||||||
dbgprintf ("Worker %p before first assignment\n", thrd_current_pointer ());
|
dbgprintf ("Worker %p before first assignment\n", thrd_current_pointer ());
|
||||||
for (i = 0; i < KEYS_COUNT; i++)
|
for (i = 0; i < KEYS_COUNT; i++)
|
||||||
{
|
{
|
||||||
*values[i] = (((unsigned int) rand () >> 3) % 1000000) * THREAD_COUNT + id;
|
*values[i] = (((unsigned long) random () >> 3) % 1000000) * THREAD_COUNT + id;
|
||||||
/* Hopefully no arithmetic overflow. */
|
/* Hopefully no arithmetic overflow. */
|
||||||
if ((*values[i] % THREAD_COUNT) != id)
|
if ((*values[i] % THREAD_COUNT) != id)
|
||||||
abort ();
|
abort ();
|
||||||
@@ -114,8 +114,8 @@ worker_thread (void *arg)
|
|||||||
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
||||||
{
|
{
|
||||||
dbgprintf ("Worker %p doing value swapping\n", thrd_current_pointer ());
|
dbgprintf ("Worker %p doing value swapping\n", thrd_current_pointer ());
|
||||||
i = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
i = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
j = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
j = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
if (i != j)
|
if (i != j)
|
||||||
{
|
{
|
||||||
unsigned int vi = *values[i];
|
unsigned int vi = *values[i];
|
||||||
|
@@ -68,7 +68,7 @@ static void
|
|||||||
perhaps_yield (void)
|
perhaps_yield (void)
|
||||||
{
|
{
|
||||||
/* This helps making the sequence of thread activations less predictable. */
|
/* This helps making the sequence of thread activations less predictable. */
|
||||||
if ((((unsigned int) rand () >> 3) % 4) == 0)
|
if ((((unsigned long) random () >> 3) % 4) == 0)
|
||||||
yield ();
|
yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ worker_thread (void *arg)
|
|||||||
/* Initialize the per-thread storage. */
|
/* Initialize the per-thread storage. */
|
||||||
for (i = 0; i < KEYS_COUNT; i++)
|
for (i = 0; i < KEYS_COUNT; i++)
|
||||||
{
|
{
|
||||||
values[i] = (((unsigned int) rand () >> 3) % 1000000) * THREAD_COUNT + id;
|
values[i] = (((unsigned long) random () >> 3) % 1000000) * THREAD_COUNT + id;
|
||||||
/* Hopefully no arithmetic overflow. */
|
/* Hopefully no arithmetic overflow. */
|
||||||
if ((values[i] % THREAD_COUNT) != id)
|
if ((values[i] % THREAD_COUNT) != id)
|
||||||
abort ();
|
abort ();
|
||||||
@@ -127,8 +127,8 @@ worker_thread (void *arg)
|
|||||||
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
||||||
{
|
{
|
||||||
dbgprintf ("Worker %p doing value swapping\n", gl_thread_self_pointer ());
|
dbgprintf ("Worker %p doing value swapping\n", gl_thread_self_pointer ());
|
||||||
i = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
i = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
j = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
j = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
if (i != j)
|
if (i != j)
|
||||||
{
|
{
|
||||||
void *vi = gl_tls_get (mykeys[i]);
|
void *vi = gl_tls_get (mykeys[i]);
|
||||||
@@ -436,7 +436,7 @@ racecheck_thread (void *arg)
|
|||||||
|
|
||||||
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
||||||
{
|
{
|
||||||
i = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
i = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
dbgprintf ("Worker %p reallocating key %d\n", gl_thread_self_pointer (), i);
|
dbgprintf ("Worker %p reallocating key %d\n", gl_thread_self_pointer (), i);
|
||||||
gl_tls_key_destroy (keys[i]);
|
gl_tls_key_destroy (keys[i]);
|
||||||
gl_tls_key_init (keys[i], destructor_table[i]);
|
gl_tls_key_init (keys[i], destructor_table[i]);
|
||||||
|
@@ -68,7 +68,7 @@ perhaps_yield (void)
|
|||||||
{
|
{
|
||||||
/* Call yield () only with a certain probability, otherwise the
|
/* Call yield () only with a certain probability, otherwise the
|
||||||
sequence of thread activations may be too predictable. */
|
sequence of thread activations may be too predictable. */
|
||||||
if ((((unsigned int) rand () >> 3) % 4) == 0)
|
if ((((unsigned long) random () >> 3) % 4) == 0)
|
||||||
yield ();
|
yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ worker_thread (void *arg)
|
|||||||
/* Initialize the per-thread storage. */
|
/* Initialize the per-thread storage. */
|
||||||
for (i = 0; i < KEYS_COUNT; i++)
|
for (i = 0; i < KEYS_COUNT; i++)
|
||||||
{
|
{
|
||||||
values[i] = (((unsigned int) rand () >> 3) % 1000000) * THREAD_COUNT + id;
|
values[i] = (((unsigned long) random () >> 3) % 1000000) * THREAD_COUNT + id;
|
||||||
/* Hopefully no arithmetic overflow. */
|
/* Hopefully no arithmetic overflow. */
|
||||||
if ((values[i] % THREAD_COUNT) != id)
|
if ((values[i] % THREAD_COUNT) != id)
|
||||||
abort ();
|
abort ();
|
||||||
@@ -127,8 +127,8 @@ worker_thread (void *arg)
|
|||||||
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
||||||
{
|
{
|
||||||
dbgprintf ("Worker %p doing value swapping\n", thrd_current_pointer ());
|
dbgprintf ("Worker %p doing value swapping\n", thrd_current_pointer ());
|
||||||
i = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
i = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
j = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
j = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
if (i != j)
|
if (i != j)
|
||||||
{
|
{
|
||||||
void *vi = tss_get (mykeys[i]);
|
void *vi = tss_get (mykeys[i]);
|
||||||
@@ -442,7 +442,7 @@ racecheck_thread (void *arg)
|
|||||||
|
|
||||||
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
|
||||||
{
|
{
|
||||||
i = ((unsigned int) rand () >> 3) % KEYS_COUNT;
|
i = ((unsigned long) random () >> 3) % KEYS_COUNT;
|
||||||
dbgprintf ("Worker %p reallocating key %d\n", thrd_current_pointer (), i);
|
dbgprintf ("Worker %p reallocating key %d\n", thrd_current_pointer (), i);
|
||||||
tss_delete (keys[i]);
|
tss_delete (keys[i]);
|
||||||
ASSERT (tss_create (&keys[i], destructor_table[i]) == thrd_success);
|
ASSERT (tss_create (&keys[i], destructor_table[i]) == thrd_success);
|
||||||
|
Reference in New Issue
Block a user