summaryrefslogtreecommitdiff
path: root/tests/barrier5.c
diff options
context:
space:
mode:
authorrpj <rpj>2001-07-09 18:22:07 +0000
committerrpj <rpj>2001-07-09 18:22:07 +0000
commit1d99828acf48bc6d5a81aadc6123e5172dfc355d (patch)
tree4646ce8ba7129298e3ca6931c8e7019e9bbeb2df /tests/barrier5.c
parentf58aab44e671bb39b8afb29804a9ca94c238c523 (diff)
* barrier.c: Revamped to fix the race condition. Two alternating
semaphores are used instead of the PulseEvent. Also improved overall throughput by returning PTHREAD_BARRIER_SERIAL_THREAD to the first waking thread. * implement.h (pthread_barrier_t_): Revamped.
Diffstat (limited to 'tests/barrier5.c')
-rw-r--r--tests/barrier5.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/tests/barrier5.c b/tests/barrier5.c
index 6576b05..77f51da 100644
--- a/tests/barrier5.c
+++ b/tests/barrier5.c
@@ -10,13 +10,13 @@
enum {
NUMTHREADS = 16,
- ITERATIONS = 10000
+ BARRIERS = 10000
};
pthread_barrier_t barrier = NULL;
pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
-int barrierReleases[ITERATIONS + 1];
+int barrierReleases[BARRIERS + 1];
void *
func(void * barrierHeight)
@@ -24,7 +24,7 @@ func(void * barrierHeight)
int i;
int result;
- for (i = 1; i < ITERATIONS; i++)
+ for (i = 1; i < BARRIERS; i++)
{
result = pthread_barrier_wait(&barrier);
@@ -38,12 +38,8 @@ func(void * barrierHeight)
*/
if (result == PTHREAD_BARRIER_SERIAL_THREAD)
{
- assert(pthread_mutex_lock(&mx) == 0);
-//printf("Releases bucket %d = %d\n", i - 1, barrierReleases[i - 1]);
-//fflush(stdout);
assert(barrierReleases[i - 1] == (int) barrierHeight);
barrierReleases[i + 1] = 0;
- assert(pthread_mutex_unlock(&mx) == 0);
}
else if (result != 0)
{
@@ -81,8 +77,8 @@ main()
assert(pthread_join(t[i], NULL) == 0);
}
- assert(barrierReleases[ITERATIONS - 1] == j);
- assert(barrierReleases[ITERATIONS] == 0);
+ assert(barrierReleases[BARRIERS - 1] == j);
+ assert(barrierReleases[BARRIERS] == 0);
assert(pthread_barrier_destroy(&barrier) == 0);
}