From Bugzilla Helper: User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) Description of problem: The sample code in the info pages for pthreads shows: pthread_cleanup_push(pthread_mutex_unlock, (void *) &mut); pthread_mutex_lock(&mut); /* do some work */ pthread_mutex_unlock(&mut); pthread_cleanup_pop(0); This code will not compile because pthread_mutex_unlock is not a true function. How reproducible: Always Steps to Reproduce: 1. Copy sample code from info pages into .c file. 2. Observe gcc errors. 3. Actual Results: Won't compile. Expected Results: Should compile. Additional info:
How exactly it does not compile? It works just fine for me (well, to get rid of warnings a (void (*)(void *)) cast is desirable). What error messages do you get? What glibc rpm version and release are you using?
I'm using glibc-2.2.2-10 (-devel and -common are also 2.2.2-10). The following code will not compile: #include <pthread.h> main() { pthread_mutex_t threads_mutex; pthread_cleanup_push(pthread_mutex_unlock, (void *)&threads_mutex); pthread_mutex_lock(&threads_mutex); if (1) { pthread_mutex_unlock(&threads_mutex); pthread_cleanup_pop(0); } else { pthread_mutex_unlock(&threads_mutex); pthread_cleanup_pop(0); } } It fails with: test.c: In function `main': test.c:7: warning: passing arg 2 of `_pthread_cleanup_push' from incompatible po inter type test.c:15: parse error before `else' test.c:18: `_buffer' undeclared (first use in this function) test.c:18: (Each undeclared identifier is reported only once test.c:18: for each function it appears in.) test.c: At top level: test.c:19: parse error before `}' I was originally mistaken - it's actually the way pthread_cleanup_push() and ..._pop() are written that makes code not compile. From looking at the preprocessor output, both the _push() and the _pop() need to be at the same level. This is nonsense, as these should be true functions.
These cannot be functions, please read the documentation: Matching pairs of `pthread_cleanup_push' and `pthread_cleanup_pop' must occur in the same function, at the same level of block nesting. Actually, `pthread_cleanup_push' and `pthread_cleanup_pop' are macros, and the expansion of `pthread_cleanup_push' introduces an open brace `{' with the matching closing brace `}' being introduced by the expansion of the matching `pthread_cleanup_pop'.