This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-17 14:39:47 UTC ---
It doesn't really help - there are more races.  The following does seem
to help though, but is certainly not applicable.

Index: gcc/libgcov.c
===================================================================
--- gcc/libgcov.c       (revision 183243)
+++ gcc/libgcov.c       (working copy)
@@ -77,6 +77,7 @@ void __gcov_merge_delta (gcov_type *coun
 #include <errno.h>
 #include <sys/stat.h>
 #endif
+#include <pthread.h>

 #ifdef L_gcov
 #include "gcov-io.c"
@@ -584,7 +585,9 @@ void
 __gcov_flush (void)
 {
   const struct gcov_info *gi_ptr;
+  static pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;

+  pthread_mutex_lock (&mx);
   gcov_exit ();
   for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
     {
@@ -598,6 +601,7 @@ __gcov_flush (void)
            ci_ptr++;
          }
     }
+  pthread_mutex_unlock (&mx);
 }

 #endif /* L_gcov */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]