On Wed, 2017-05-31 at 23:54 +0200, Philippe Waroquiers wrote:
> If the problem is effectively linked to re-creation of
> another mutex at the same addr, then i think a small
> reproducer should be easy to write.
The below small program reproduces the behaviour
you have seen: a race condition is reported between
2 threads while helgrind reports they are holding
the same lock.
But in reality, the lock was destroyed and re-created.
Helgrind falsely believes this to be the same lock
(and falsely reports that the first time the lock was observed
is the re-creation).
So, it is probable that what you see is a similar case.
In absence of another synchronisation than this (falsely
presented as a common) lock, you might have a real race
condition.
Philippe
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
pthread_mutex_t mx1;
int x = 0;
void* child_fn ( void* arg )
{
int r;
int destroy;
printf("child_fn\n");
r= pthread_mutex_lock(&mx1); assert(!r);
x += 1;
destroy = x == 1;
r= pthread_mutex_unlock(&mx1); assert(!r);
if (destroy) {
printf("destroy/recreate mx1\n");
r= pthread_mutex_destroy(&mx1); assert(!r);
r= pthread_mutex_init(&mx1, NULL); assert(!r);
}
printf("child_fn returning ...\n");
return NULL;
}
void* child_fn2 ( void* arg )
{
sleep (20);
child_fn ( arg );
return NULL;
}
int main ( int argc, char** argv )
{
pthread_t child1, child2;
int r;
r= pthread_mutex_init(&mx1, NULL); assert(!r);
printf("creating threads\n");
r= pthread_create(&child1, NULL, child_fn, NULL); assert(!r);
r= pthread_create(&child2, NULL, child_fn2, NULL); assert(!r);
printf("sleeping 5\n");
sleep (5);
printf("joining child1\n");
r= pthread_join(child1, NULL); assert(!r);
printf("joining child2\n");
r= pthread_join(child2, NULL); assert(!r);
printf("end\n");
return 0;
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users