This is the mail archive of the libc-help@sourceware.org mailing list for the glibc 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]

Re: pthread_create()'s behavor?


Arrgg, gotchu.

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.


Cheers,
Hei



----- Original Message -----
From: Paul Pluzhnikov <ppluzhnikov@google.com>
To: Hei Chan <structurechart@yahoo.com>
Cc: "libc-help@sourceware.org" <libc-help@sourceware.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 <structurechart@yahoo.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
triggers A::~A()).

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.

Cheers,
-- 
Paul Pluzhnikov



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