Bug 46516 - pthread functions declared as macros instead of functions
Summary: pthread functions declared as macros instead of functions
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc   
(Show other bugs)
Version: 7.0
Hardware: i586 Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Aaron Brown
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-06-29 03:55 UTC by John William
Modified: 2016-11-24 15:01 UTC (History)
1 user (show)

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


Attachments (Terms of Use)

Description John William 2001-06-29 03:55:24 UTC
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 15:03:55 UTC
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 04:28:40 UTC
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 08:22:19 UTC
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.