yes.
> It's not a major issue, because the leak only occur when you exit the
> application (and the static members are not being free as they
> should), but I would like to know if you are aware of this issue, and
> is there a workaround or any other solution?
it's major issue if PB used in shared library with load/call/unload usage pattern :(
--
Ivan Kharin
Isn't this a common scenario in C++ for which stdlib provides a simple
solution, std::auto_ptr? std::auto_ptr is a lightweight class designed
to "RAIIify" pointers. What am I missing?
I'm referring to having a static auto_ptr variable. I'm not familiar
with how this can manifest the danger you describe. Can you point it
out in the following example?
#include <pthread.h>
#include <memory>
#include <iostream>
class B
{
public:
~B()
{
std::cout<<"destructor called"<<std::endl;
}
int alive()
{
return 1;
}
};
class A
{
public:
static std::auto_ptr<B> b;
};
std::auto_ptr<B> A::b(new B);
void *threadFunc(void* p)
{
while(1)
{
std::cout<<A::b->alive()<<" ";
}
}
int main()
{
pthread_t t;
int rc;
int p;
rc = pthread_create(&t, NULL, threadFunc, (void *)p);
sleep(1);
return 1;
}
Also I found that static vars local to the thread function get deleted
before the thread gets killed.
Static is dangerous in multithreaded scenarios for obvious reasons.
These issues just add more complications.
Marc
Ok, thanks. There are other problems though. If A::b was a B* instead
of a std::auto_ptr<B>, then the data that A::b points to will be ok
because it won't be deleted. However, A::b would get deleted so access
to the data via A::b may be undefined.
Also I found that static vars local to the thread function get deleted
before the thread gets killed.
Static is dangerous in multithreaded scenarios for obvious reasons.
These issues just add more complications.
Except that you still have the shared lib load/unload problem :)
Marc
Except that you still have the shared lib load/unload problem :)