Skip to content

Commit bfe5fc6

Browse files
authored
Merge pull request #9457 from awlauria/re_enable_threads_check
test/threads: Re-enable tests.
2 parents b723513 + 736e244 commit bfe5fc6

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

test/threads/Makefile.am

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ check_PROGRAMS = \
2828
opal_condition \
2929
opal_atomic_thread_bench
3030

31-
# JMS possibly to be re-added when #1232 is fixed
32-
#TESTS = $(check_PROGRAMS)
33-
TESTS =
31+
TESTS = $(check_PROGRAMS)
3432

3533
opal_thread_SOURCES = opal_thread.c
3634
opal_thread_LDADD = \

test/threads/opal_condition.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,46 @@ static volatile int thr2_count = 0;
4040

4141
static void *thr1_run(opal_object_t *obj)
4242
{
43-
int i;
4443
clock_t c1, c2;
45-
opal_mutex_lock(&mutex);
4644
c1 = clock();
47-
for (i = 0; i < TEST_COUNT; i++) {
48-
opal_condition_wait(&thr1_cond, &mutex);
49-
opal_condition_signal(&thr2_cond);
45+
opal_mutex_lock(&mutex);
46+
while (TEST_COUNT != thr1_count) {
5047
thr1_count++;
48+
opal_condition_signal(&thr2_cond);
49+
opal_condition_wait(&thr1_cond, &mutex);
5150
}
52-
c2 = clock();
51+
52+
// Whoever gets here first needs to alert the other
53+
// thread for their last iteration.
54+
opal_condition_signal(&thr2_cond);
5355
opal_mutex_unlock(&mutex);
54-
fprintf(stderr, "thr1: time per iteration: %ld usec\n", (long) ((c2 - c1) / TEST_COUNT));
56+
c2 = clock();
57+
fprintf(stderr, "thr1: time per iteration: %ld uses\n", (long)((c2 - c1) / TEST_COUNT));
5558
return NULL;
5659
}
5760

5861
static void *thr2_run(opal_object_t *obj)
5962
{
60-
int i;
6163
clock_t c1, c2;
62-
opal_mutex_lock(&mutex);
6364
c1 = clock();
64-
for (i = 0; i < TEST_COUNT; i++) {
65+
opal_mutex_lock(&mutex);
66+
while(TEST_COUNT != thr2_count) {
67+
thr2_count++;
6568
opal_condition_signal(&thr1_cond);
6669
opal_condition_wait(&thr2_cond, &mutex);
67-
thr2_count++;
6870
}
69-
c2 = clock();
71+
72+
// Whoever gets here first needs to alert the other
73+
// thread for the last iteration.
74+
opal_condition_signal(&thr1_cond);
7075
opal_mutex_unlock(&mutex);
71-
fprintf(stderr, "thr2: time per iteration: %ld usec\n", (long) ((c2 - c1) / TEST_COUNT));
76+
77+
c2 = clock();
78+
fprintf(stderr, "thr2: time per iteration: %ld usec\n", (long)((c2 - c1) / TEST_COUNT));
7279
return NULL;
7380
}
7481

82+
7583
int main(int argc, char **argv)
7684
{
7785
int rc;

0 commit comments

Comments
 (0)