https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80408
--- Comment #5 from Janne Blomqvist <jb at gcc dot gnu.org> --- (In reply to Raphael Monod from comment #4) > Thank you for your answer. But I don't understand why adding -lpthread > option change the behavior if I do not use any thread. In libgfortran, if a thread library is not linked in, thread-related stuff such as mutexes are stubbed out in order to improve performance. With -lpthread it's thus more likely that the code deadlocks. Note that there's no guarantee it works without -lpthread either, it's just an accident. > Moreover, if I refer > to this page ( > https://docs.oracle.com/cd/E19455-01/806-5257/gen-26/index.html ) write > statement seems to be async-signal safe ? Where am I wrong ? > Finaly, what can I do if I want to print a message in my trap function ? > Thank you for your interest to my problem. That link refers to the POSIX write() function, which is a much lower level interface than the Fortran write statement. POSIX write() is async-signal-safe, but Fortran write has no such guarantees. As the things you can do in a signal handler is extremely limited, one way to handle it is to just set a flag variable, and then in the normal code you regularly check that flag variable, and print messages or whatever. Another way is the so-called self-pipe trick, where you create a pipe, and the signal handler can then write to the pipe. A thread in your program can then poll on the other end of the pipe. Handling pipes, and the need to use POSIX write/read rather than Fortran READ/WRITE probably means you'll have to implement that part of the program in C.