This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 18 Jan 2012 10:38:15 +0000
- Subject: [Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
- Auto-submitted: auto-generated
- References: <bug-49484-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484
--- Comment #8 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-18 10:38:15 UTC ---
(In reply to comment #5)
> 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 */
Would be applicable when we compile a second libgcov_r which we'd use
when linking with -pthread.