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

            Bug ID: 67493
           Summary: -fcheck=recursive not thread aware
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: franke.daniel at gmail dot com
  Target Milestone: ---

Hi all.

It seems that the checks done by -fcheck=recursive are not thread aware. In the
example below, the PURE procedure 'worker' is not called recursively, but in
parallel, still the recursion check triggers. I believe that there should be no
error in such a situation.

To note: declaring 'worker' RECURSIVE or not using -fcheck-recursive does not
trigger any runtime errors.


$ cat worker.f90
PURE SUBROUTINE worker(n, sumn) BIND(C)
  USE ISO_C_BINDING

  INTEGER(C_INT), INTENT(in)  :: n
  INTEGER(C_INT), INTENT(out) :: sumn
  INTEGER :: k

  sumn = 0
  DO k = 1, n
    sumn = sumn + k
  END DO
END SUBROUTINE

$ cat main.c
#include <pthread.h>

void worker(int*, int*);

void* controller(void *p) {
  int n = 100000, sumn;
  worker(&n, &sumn);
}

int main(int argc, char **argv) {
  pthread_t t1, t2;

  pthread_create(&t1, NULL, controller, NULL);
  pthread_create(&t2, NULL, controller, NULL);

  pthread_join(t1, NULL);
  pthread_join(t2, NULL);

  return 0;
}

$ gfortran --version
[...]
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)

$ gfortran main.c worker.f90 -fcheck=recursion -lpthread && ./a.out 
At line 3 of file worker.f90
Fortran runtime error: Recursive call to nonrecursive procedure 'worker'


$ gfortran --version 
GNU Fortran (GCC) 5.2.0

$ gfortran main.c worker.f90 -fcheck=recursion -lpthread && ./a.out
At line 1 of file worker.f90
Fortran runtime error: Recursive call to nonrecursive procedure 'worker'

Reply via email to