https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122787

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
After quite a bit of studying this, I am covinced this is not a failure of
caf_shmem.

The test is on a non-blocking lock from the days od -fcoarray=single. With a
single image it is guranteed to acquire the lock.

However, with multiple images there is no guarantee as the aquired variable can
be false if another image is busy trying to aquire the lock.

The only thing we need to do here loop around until the LOCK is actually
acquired:

use iso_fortran_env
implicit none

type(lock_type) :: lock[*]
integer :: stat
integer :: counter
logical :: acquired

LOCK(lock)
UNLOCK(lock)

stat = 99
LOCK(lock, stat=stat)
if (stat /= 0) STOP 1

stat = 99
UNLOCK(lock, stat=stat)
if (stat /= 0) STOP 2

acquired = .false.
counter = 0
do while (.not. acquired)
  counter = counter + 1
  LOCK (lock[this_image()], acquired_lock=acquired)
  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

Reply via email to