This is the mail archive of the
mailing list for the glibc project.
Re: pthread_create()'s behavor?
I actually doesn't have anything in the destructor on production (no memory leak tho since the only time the destructor is called is when my application is shutdown).
The sample code I provided in this email chain includes the cleanup in the destructor to make valgrind happy only.
Let me try to change the destructor and run with Thread Sanitizer (never used it before.? seems like a very useful tool.).
Thanks in advance.
----- Original Message -----
From: Paul Pluzhnikov <email@example.com>
To: Hei Chan <firstname.lastname@example.org>
Cc: "email@example.com" <firstname.lastname@example.org>
Sent: Tuesday, April 17, 2012 4:34 PM
Subject: Re: pthread_create()'s behavor?
On Tue, Apr 17, 2012 at 4:28 PM, Hei Chan <email@example.com> wrote:
> Any hint?
The problem is that you are *destructing* the map (and the A object which
contains it) in thread T0, while your other thread T1 is still accessing it.
You need to wait for T1 to finish before returning from main (which
One way to achieve this is to make "thread" a member variable of A, and
to call pthread_join() in A::~A(). You should also *not* detach the thread.