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?


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]