public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "martin.diehl at kuleuven dot be" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/101824] New: VOLATILE not honored
Date: Mon, 09 Aug 2021 06:30:48 +0000	[thread overview]
Message-ID: <bug-101824-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 101824
           Summary: VOLATILE not honored
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: martin.diehl at kuleuven dot be
  Target Milestone: ---

I have a wrapper to C to control a Fortran program with IPC signals:


/* c_interface.c */
#include <signal.h>

void signalterm_c(void (*handler)(int)){
  signal(SIGTERM, handler);
}

void signalusr1_c(void (*handler)(int)){
  signal(SIGUSR1, handler);
}



! c_interface.f90
module c_interface

  implicit none
  interface

  subroutine signalterm_C(handler) bind(C)
    use, intrinsic :: ISO_C_Binding, only: C_FUNPTR

    type(C_FUNPTR), intent(in), value :: handler
  end subroutine signalterm_C

  subroutine signalusr1_C(handler) bind(C)
    use, intrinsic :: ISO_C_Binding, only: C_FUNPTR

    type(C_FUNPTR), intent(in), value :: handler
  end subroutine signalusr1_C

  end interface

end module c_interface


! wait_for_SIGTERM.f90
program wait_for_SIGTERM
  use, intrinsic :: ISO_C_binding

  use c_interface

  implicit none
  logical, volatile :: &
    interface_SIGTERM, &  ! termination signal
    interface_SIGUSR1     ! 1. user-defined signal

  call init

  do while( .not. interface_SIGTERM)


  enddo

contains

subroutine init()

  call signalterm_c(c_funloc(catchSIGTERM))
  call signalusr1_c(c_funloc(catchSIGUSR1))
  call interface_setSIGTERM(.false.)
  call interface_setSIGUSR1(.false.)

end subroutine init


subroutine catchSIGTERM(signal) bind(C)

  integer(C_INT), value :: signal


  print'(a,i0)', ' received signal ',signal
  call interface_setSIGTERM(.not. interface_SIGTERM)

end subroutine catchSIGTERM


subroutine catchSIGUSR1(signal) bind(C)

  integer(C_INT), value :: signal


  print'(a,i0)', ' received signal ',signal
  call interface_setSIGUSR1(.not. interface_SIGUSR1)

end subroutine catchSIGUSR1


subroutine interface_setSIGTERM(state)

  logical, intent(in) :: state


  interface_SIGTERM = state
  print*, 'set SIGTERM to',state

end subroutine interface_setSIGTERM


subroutine interface_setSIGUSR1(state)

  logical, intent(in) :: state


  interface_SIGUSR1 = state
  print*, 'set SIGUSR1 to',state

end subroutine interface_setSIGUSR1

end program



Compile and run (tested on Linux):

gfortran c_interface.c c_interface.f90 wait_for_SIGTERM.f90 -o wait
./wait&
kill -SIGUSR1 XXXX
kill -SIGUSR1 XXXX
kill -SIGTERM XXXX

If compiled without optimization flag, the loop exits on SIGTERM (indented
behavior). If compiled with `-O3`, it runs forever. This behavior is
independent of the VOLATILE attribute.

There is a little discussion on
https://fortran-lang.discourse.group/t/volatile-needed/1648

             reply	other threads:[~2021-08-09  6:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09  6:30 martin.diehl at kuleuven dot be [this message]
2021-08-09  7:49 ` [Bug tree-optimization/101824] " rguenth at gcc dot gnu.org
2021-08-09  8:06 ` rguenth at gcc dot gnu.org
2021-08-10  8:08 ` cvs-commit at gcc dot gnu.org
2021-08-10  8:10 ` [Bug tree-optimization/101824] [9/10/11 Regression] " rguenth at gcc dot gnu.org
2021-09-06  8:50 ` cvs-commit at gcc dot gnu.org
2021-10-13 11:08 ` [Bug tree-optimization/101824] [9/10 " cvs-commit at gcc dot gnu.org
2021-11-08 14:07 ` [Bug tree-optimization/101824] [9 " cvs-commit at gcc dot gnu.org
2021-11-08 14:07 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101824-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).