Skip to content

Commit 7901d0b

Browse files
committed
Issue 907: Make 5.1/atomic/test_atomic_fail_*.{c,F90} less racy
The current code sets 'y = 1' and then atomically 'x = 10' in the first thread, expecting that once 'y' shows up as updated in the second thread, 'x' is also updated. - But this is racy. With this commit, 'y' is set non atomically after the atomic write. This applies to all 6 tests: tests/5.1/atomic/test_atomic_fail_{acquire,relexed,seq_cst}.{c,F90}.
1 parent 4843b5a commit 7901d0b

6 files changed

Lines changed: 6 additions & 6 deletions

tests/5.1/atomic/test_atomic_fail_acquire.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ INTEGER FUNCTION test_atomic_fail_acquire()
3636
!$omp parallel num_threads(2) private(thrd)
3737
thrd = omp_get_thread_num()
3838
IF( thrd .EQ. 0 ) THEN
39-
y = 1
4039
!$omp atomic write seq_cst
4140
x = 10
4241
!$omp end atomic
42+
y = 1
4343
ELSE
4444
DO WHILE ( y .NE. 5 )
4545
!$omp atomic compare seq_cst fail(acquire)

tests/5.1/atomic/test_atomic_fail_acquire.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ int test_atomic_fail_acquire() {
2525
{
2626
int thrd = omp_get_thread_num();
2727
if (thrd == 0) {
28-
y = 1;
2928
#pragma omp atomic write seq_cst
3029
x = 10;
30+
y = 1;
3131
} else {
3232
while (y != 5) {
3333
#pragma omp atomic compare seq_cst fail(acquire)

tests/5.1/atomic/test_atomic_fail_relaxed.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ INTEGER FUNCTION test_atomic_fail_relaxed()
3636
!$omp parallel num_threads(2) private(thrd)
3737
thrd = omp_get_thread_num()
3838
IF( thrd .EQ. 0 ) THEN
39-
y = 1
4039
!$omp atomic write seq_cst
4140
x = 10
4241
!$omp end atomic
42+
y = 1
4343
ELSE
4444
DO WHILE ( y .NE. 5 )
4545
!$omp atomic compare fail(relaxed)

tests/5.1/atomic/test_atomic_fail_relaxed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ int test_atomic_fail_relaxed() {
2525
{
2626
int thrd = omp_get_thread_num();
2727
if (thrd == 0) {
28-
y = 1;
2928
#pragma omp atomic write seq_cst
3029
x = 10;
30+
y = 1;
3131
} else {
3232
while (y != 5) {
3333
#pragma omp atomic compare fail(relaxed)

tests/5.1/atomic/test_atomic_fail_seq_cst.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ INTEGER FUNCTION test_atomic_fail_seq_cst()
3737
!$omp parallel num_threads(2) private(thrd, tmp)
3838
thrd = omp_get_thread_num()
3939
IF( thrd .EQ. 0 ) THEN
40-
y = 1
4140
!$omp atomic write seq_cst
4241
x = 10
4342
!$omp end atomic
43+
y = 1
4444
ELSE
4545
tmp = 0
4646
DO WHILE ( y .NE. 5 )

tests/5.1/atomic/test_atomic_fail_seq_cst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ int test_atomic_fail_seq_cst() {
2525
{
2626
int thrd = omp_get_thread_num();
2727
if (thrd == 0) {
28-
y = 1;
2928
#pragma omp atomic write seq_cst
3029
x = 10;
30+
y = 1;
3131
} else {
3232
while (y != 5) {
3333
#pragma omp atomic compare acquire fail(seq_cst)

0 commit comments

Comments
 (0)