Bug 46516 - pthread functions declared as macros instead of functions
pthread functions declared as macros instead of functions
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
7.0
i586 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Aaron Brown
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-06-28 23:55 EDT by John William
Modified: 2007-04-18 12:34 EDT (History)
0 users

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


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);
     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:
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>

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.
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.