pthread_create()'s behavor?

Paul Pluzhnikov ppluzhnikov@google.com
Tue Apr 17 23:36:00 GMT 2012


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



More information about the Libc-help mailing list