Boost logo

Boost Users :

From: STenyaK (Bruno Gonzalez) (stenyak_at_[hidden])
Date: 2007-12-18 05:43:45


I haven't been able to find any clear explanation about this, so here it goes:

I'm coding a multithreaded program using pthreads. The general
behaviour is this:

-A function starts.
-The function creates a shared pointer "OBJ".
-The function creates a Thread, passing "OBJ" as the parameter (having
to cast it as void*).
-The thread starts, getting a (void*) param which is casted back to
"OBJ" (shared pointer type).
-The function ends, and therefore its "OBJ" goes out of scope.
-The thread" ends, so its "OBJ" goes out of scope too.
(of course, the thread could at times end before the function instead)

I'm afraid that the shared pointer does not behave well due to those
nasty void* casts... maybe trying to delete twice the object.
What's the proper way of coding this? Weak pointers maybe?

Thanks a lot for any help.

-- 
Saludos,
     Bruno González
_______________________________________________
Msn/Jabber: stenyak AT gmail.com
ICQ: 153709484
http://www.stenyak.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net