Home > Archive > Unix Programming > June 2007 > NPTL, C++ and Cleanup
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
NPTL, C++ and Cleanup
|
|
| uljanow 2007-06-19, 4:16 am |
| hi,
I was wondering why in the following code example the destructor isn't
called by the cleanup handler:
....
struct foo;
void* thread_start(void*) {
foo* ptr = new foo;
pthread_cleanup_push((operator delete), ptr);
// Do something
pthread_cleanup_pop(0);
return NULL;
}
struct foo {
int a, b, c;
foo() {}
~foo() { fprintf(stderr, "destruc\n"); }
};
.....
Using another function which just calls delete works however.
Regards
S. Sakar
| |
| Maxim Yegorushkin 2007-06-19, 4:16 am |
| On 19 Jun, 08:30, uljanow <ssa...@gmx.de> wrote:
> I was wondering why in the following code example the destructor isn't
> called by the cleanup handler:
> ...
> struct foo;
>
> void* thread_start(void*) {
> foo* ptr = new foo;
> pthread_cleanup_push((operator delete), ptr);
> // Do something
> pthread_cleanup_pop(0);
> return NULL;
>
> }
>
> struct foo {
> int a, b, c;
> foo() {}
> ~foo() { fprintf(stderr, "destruc\n"); }};
>
> ....
> Using another function which just calls delete works however.
You may be confusing C++ keyword delete with operator delete, which
are different things. For more info please see
http://groups.google.co.uk/group/co...769651f6c9ba195
| |
| uljanow 2007-06-19, 4:16 am |
| > You may be confusing C++ keyword delete with operator delete, which
> are different things. For more info please see
> http://groups.google.co.uk/group/co...769651f6c9ba195
Thanks, not knowing the difference was the problem.
I think I'll use auto_ptr's instead.
| |
|
|
|
|
|