incorrect define for pthread_cleanup_push
I'm programming an application in Solaris 10 using Sun Studio 11. That application manages threads for communication.
I must use the function [b]pthread_cleanup_push[/b] to control when the thread finishes. But I found that when I used it the compilation failed, and just commenting this line the compilation worked fine.
So I've found that the macro for [b]pthread_cleanup_push[/b] in [u]pthread.h[/u]>contains a missing {.
This is the definition I've in the version of pthread.h that I've installed:
[i]#define pthread_cleanup_push(routine, args) [b]{ [/b]\
_cleanup_t _cleanup_info; \
__pthread_cleanup_push((_Voidfp)(routine), (void *)(args), \
(caddr_t)_getfp(), &_cleanup_info);[/i]
Obviously the { its a annoying :-)
# 1
Sorry, RTFM in this case:
http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_cleanup_push.html
"These functions may be implemented as macros and will appear as statements and in pairs within
the same lexical scope (that is, the pthread_cleanup_push() macro may be thought to expand to a
token list whose first token is `{' with pthread_cleanup_pop() expanding to a token list whose last
token is the corresponding `}'."
regards,
__Fedor.
SFVa at 2007-7-12 23:57:07 >

# 2
The Solaris system generates a compile time error if
pthread_cleanup_push()doesnothaveamatching
pthread_cleanup_pop().
(taken from the solaris man page)
Linux does exactly the same and one can read in its pthread.h:
pthread_cleanup_push and pthread_cleanup_pop are macros and must always
be used in matching pairs at the same nesting level of braces.