Hi Robert,

Ok in my game when i load a ressource i do it in a thread. I dont
allocate a thread pool. i just create one thread per load sequence. For
example when i create a player i craete one thread with a list of files
to load. During the game a player can arrive and leave. So there will be
a lot of thread creation and destruction when the game run a long time.
It's a simplified view but it's the idea.

Without my modification in my code when i created a thread load data and
delete it. The thread resource was not clear, it's still valid even if
finish. So after one day of game running i had 3Gb of finished thread
and deleted but without ressources released.

http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_detach.3.html
http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_join.3.html


I tested two behaviours with join and detach. Both work:
If i call detach after the creation of my thread the resources are released 
when deleted.
And if i call join when the thread is finish the resources are also released.

http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_create.3.html
in the notes section they explain the stuff about the resources.

I give pointer to doc only because it explains better than i could, I think 
you already know those doc.



to do the test do something like that:

int main(int argc, char** argv)
{
        {
        create 200 threads
        run them
        when all are finished delete them
        }
        sleep( 1000);
        // check your system memory and virtual memory
        return 0
}


I am not sure if we need to fix this inside osg, i mean calling detach do what 
is expected.
Just user must be aware about this behaviour.

I hope i explained correctly

Cheers,
Cedric

-- 
+33 659 598 614  Cedric Pinson mailto:[email protected]
http://www.plopbyte.net


On Mon, 2009-11-30 at 10:47 +0000, Robert Osfield wrote:
> HI Cedric,
> 
> On Sun, Nov 29, 2009 at 11:02 PM, Cedric Pinson
> <[email protected]> wrote:
> > Ok reading the code and the doc of pthread, in order to have the
> > ressource freed at the end of the thread, i must call detach(). now i
> > have my memory back
> >
> > maybe it could help for others that create thread in application on a
> > long period
> 
> Could you explain a bit more how you are using threads/how you are
> finishing them/destructing.
> 
> Is there something missing from OpenThreads Thread destruction?
> 
> Robert.
> 

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to