The testcase would fail occasionally with multiple images because the
use of acquired_lock is a non-blocking LOCK. Only UNLOCK this if the
LOCK was acquired. Keep track of the loop count and bail out if the
limit is reached.
During testing it was observed that the loop count could go as high as
33 times depending on system conditions, running the test outside the
testsuite 1000's of times.
PR fortran/121429
gcc/testsuite/ChangeLog:
* gfortran.dg/coarray/lock_1.f90: Updated.
!
! PR fortran/18918
!
-
use iso_fortran_env
implicit none
type(lock_type) :: lock[*]
integer :: stat
+integer :: counter
logical :: acquired
LOCK(lock)
stat = 99
LOCK(lock, stat=stat)
if (stat /= 0) STOP 1
+
stat = 99
UNLOCK(lock, stat=stat)
if (stat /= 0) STOP 2
-if (this_image() == 1) then
- acquired = .false.
+acquired = .false.
+counter = 0
+do while (.not. acquired)
+ counter = counter + 1
LOCK (lock[this_image()], acquired_lock=acquired)
- if (.not. acquired) STOP 3
- UNLOCK (lock[1])
-end if
+ if (acquired) UNLOCK (lock)
+ if ((num_images() .eq. 8) .and. (counter .gt. 100)) exit
+end do
+! counter here can vary depending on conditions, picked 100.
+if (counter .gt. 100) stop counter
end
-