Passing a pointer to a structure as an argument to a thread cancellation cleanup handler?

The main problem is that you are missing the call to.

The main problem is that you are missing the call to pthread_cleanup_pop(0) after the 'function continues' comment. That will make the compiler fail. Check out sample code using push/pop at opengroup.org.

You also have a few other problems there, as pointed out in other answers. Here is something that at least compiles after fixing all the compiler errors: #include typedef struct struct_def { /* data */ } struct_def; struct_def *ptr_to_struct_def; void cleanup (void *arg) { /* Do your cleanup for the thread here */ } void * thread_function(void *arg) { pthread_cleanup_push(cleanup, (void *)ptr_to_struct_def); /* correct? */ /* Function continues */ pthread_cleanup_pop (0); } int main() { int err; pthread_t tid; err = pthread_create(&tid, NULL, thread_function, (void *)1); /* main continues */ }.

Good catch! I hate macros that don't expand to complete compilable blocks ... – Nikolai N Fetissov Nov 13 '09 at 22:07.

I don't see the assignment ptr_to_struct_def = &struct_def; in the code you posted. Wait ... did you say compiler? If this doesn't compile - post the compiler error.

Though I don't think you meant that. OK, you did mean that :) Thanks to @Gonzalo I looked into the /usr/include/pthread. H and sure enough the push/pop are macros (at least on Linux here): # define pthread_cleanup_push(routine, arg) \ do { \ __pthread_cleanup_class __clframe (routine, arg) ... # define pthread_cleanup_pop(execute) \ __clframe.

__setdoit (execute); \ } while (0) What an unpleasant surprise ...

1 for taking the time to check the header file. – Gonzalo Nov 13 '09 at 22:27 They are required to be macros like this. – R.. Apr 23 at 22:07 From pubs.opengroup.Org/onlinepubs/009695399/functions/…: "These functions may be implemented as macros.

" - doesn't seem like required to me. Whether they can be implemented in any other way is a different question. – Nikolai N Fetissov Apr 24 at 16:22.

With that code, the ptr_to_struct_def is undefined/uninitialized that cannot work. It should point to some instance of struct_def. Also I think it is quite uncommon to pass (void*)1 for unused arguments, just use 0 if you don't use the value.

Function continues */ } int main() { int err; pthread_t tid; err = pthread_create(&tid1, NULL, thread_function, (void *)1); /* main continues */ }.

Typedef struct { } struct_def; struct_def *ptr_to_struct_def; void * thread_function(void *arg) int main() { int err,iResult; pthread_attr_t sThreadAttr; iResult = pthread_attr_init(&sThreadAttr); assert(iResult==0); pthread_t tid; err = pthread_create(&tid1, &sThreadAttr, thread_function, (void *)&ptr_to_struct_def); iResult = pthread_join(sThread, NULL); assert(iResult==0); /* main continues */ #else thread_function(); #endif // the end return 0; } void * thread_function(void *arg) { }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions