]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Adjust test to work with multiple images.
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 14 Feb 2026 23:46:44 +0000 (15:46 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 26 Feb 2026 17:18:25 +0000 (09:18 -0800)
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.

gcc/testsuite/gfortran.dg/coarray/lock_1.f90

index 1ec5984a4d347ac2d38390a57beb125060aa6302..d990fd3f908c4a5c6bd4983e88aa36bc08847724 100644 (file)
@@ -4,12 +4,12 @@
 !
 ! PR fortran/18918
 !
-
 use iso_fortran_env
 implicit none
 
 type(lock_type) :: lock[*]
 integer :: stat
+integer :: counter
 logical :: acquired
 
 LOCK(lock)
@@ -18,15 +18,19 @@ UNLOCK(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
-