Bug 46516 - pthread functions declared as macros instead of functions
pthread functions declared as macros instead of functions
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i586 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Aaron Brown
Depends On:
  Show dependency treegraph
Reported: 2001-06-28 23:55 EDT by John William
Modified: 2016-11-24 10:01 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-07-24 00:28:44 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description John William 2001-06-28 23:55:24 EDT
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);
     /* do some work */

This code will not compile because pthread_mutex_unlock is not a true 

How reproducible:

Steps to Reproduce:
1. Copy sample code from info pages into .c file.
2. Observe gcc errors.

Actual Results:  Won't compile.

Expected Results:  Should compile.

Additional info:
Comment 1 Jakub Jelinek 2001-07-23 11:03:55 EDT
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?
Comment 2 John William 2001-07-24 00:28:40 EDT
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>

  pthread_mutex_t threads_mutex;

  pthread_cleanup_push(pthread_mutex_unlock, (void *)&threads_mutex);

  if (1)

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.
Comment 3 Jakub Jelinek 2001-07-24 04:22:19 EDT
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'.

Note You need to log in before you can comment on or make changes to this bug.