pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Mikolaj Golub
Hi,

I have problems with compiling our application under 8.0.

It fails due to these definitions in pthread.h that look like a typo or
incorrectly applied patch:

170 #define pthread_cleanup_push(cleanup_routine, cleanup_arg)  
\
171 {   
\
172 struct _pthread_cleanup_info __cleanup_info__;  
\
173 __pthread_cleanup_push_imp(cleanup_routine, 
cleanup_arg,\
174 __cleanup_info__); 
\
175 {
176 
177 #define pthread_cleanup_pop(execute)
\
178 }   
\
179 __pthread_cleanup_pop_imp(execute); 
\
180 }


This patch fixes the problem for me:

--- pthread.h.orig2009-11-24 16:44:13.0 +0200
+++ pthread.h   2009-11-24 16:44:45.0 +0200
@@ -172,10 +172,10 @@
struct _pthread_cleanup_info __cleanup_info__;  
\
__pthread_cleanup_push_imp(cleanup_routine, 
cleanup_arg,\
__cleanup_info__); 
\
-   {
+   }   
 
 #definepthread_cleanup_pop(execute)
\
-   }   
\
+   {   \
__pthread_cleanup_pop_imp(execute); 
\
}

-- 
Mikolaj Golub
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread pluknet
2009/11/24 Mikolaj Golub to.my.troc...@gmail.com:
 Hi,

 I have problems with compiling our application under 8.0.

 It fails due to these definitions in pthread.h that look like a typo or
 incorrectly applied patch:

    170 #define         pthread_cleanup_push(cleanup_routine, cleanup_arg)     
          \
    171                 {                                                      
          \
    172                         struct _pthread_cleanup_info __cleanup_info__; 
          \
    173                         __pthread_cleanup_push_imp(cleanup_routine, 
 cleanup_arg,\
    174                                 __cleanup_info__);                    
          \
    175                         {
    176
    177 #define         pthread_cleanup_pop(execute)                           
          \
    178                         }                                              
          \
    179                         __pthread_cleanup_pop_imp(execute);            
          \
    180                 }


Hi.

No, this is made intentionally.
P.S. I don't understand the reason in the second brackets pair though
(lines 175,178),
 maybe these are because of comment to v1.43..

-- 
wbr,
pluknet
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org

Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Mikolaj Golub
On Tue, 24 Nov 2009 16:53:35 +0200 Mikolaj Golub wrote:

 Hi,

 I have problems with compiling our application under 8.0.

 It fails due to these definitions in pthread.h that look like a typo or
 incorrectly applied patch:

 170 #define pthread_cleanup_push(cleanup_routine, cleanup_arg)
   \
 171 { 
   \
 172 struct _pthread_cleanup_info 
 __cleanup_info__;  \
 173 __pthread_cleanup_push_imp(cleanup_routine, 
 cleanup_arg,\
 174 __cleanup_info__);   
   \
 175 {
 176 
 177 #define pthread_cleanup_pop(execute)  
   \
 178 } 
   \
 179 __pthread_cleanup_pop_imp(execute);   
   \
 180 }


 This patch fixes the problem for me:

I was hurry when said that the patch fixed the problem. The application
compiled but later it crashed in pthread_cleanup_pop:

(gdb) bt
#0  0xbf4f9ee0 in ?? ()
#1  0x287d18c9 in __pthread_cleanup_pop_imp () from /lib/libthr.so.3
#2  0x287d18ed in pthread_cleanup_pop () from /lib/libthr.so.3
#3  0x287d123c in pthread_exit () from /lib/libthr.so.3
#4  0x287c7757 in pthread_getprio () from /lib/libthr.so.3
#5  0x in ?? ()

So, I don't know what these macros actually were supposed to be. They were
introduced in r179662:

Revision 1.43: download - view: text, markup, annotated - select for diffs
Mon Jun 9 01:14:10 2008 UTC (17 months, 2 weeks ago) by davidxu
Branches: MAIN
Diff to: previous 1.42: preferred, colored
Changes since revision 1.42: +21 -2 lines

SVN rev 179662 on 2008-06-09 01:14:10Z by davidxu

Make pthread_cleanup_push() and pthread_cleanup_pop() as a pair of macros,
use stack space to keep cleanup information, this eliminates overhead of
calling malloc() and free() in thread library.

Discussed on: thread@

 --- pthread.h.orig2009-11-24 16:44:13.0 +0200
 +++ pthread.h   2009-11-24 16:44:45.0 +0200
 @@ -172,10 +172,10 @@
 struct _pthread_cleanup_info __cleanup_info__;
   \
 __pthread_cleanup_push_imp(cleanup_routine, 
 cleanup_arg,\
 __cleanup_info__);   
   \
 -   {
 +   }   
  
  #definepthread_cleanup_pop(execute)  
   \
 -   } 
   \
 +   {   \
 __pthread_cleanup_pop_imp(execute);   
   \
 }

-- 
Mikolaj Golub
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Tom Evans
On Tue, Nov 24, 2009 at 3:18 PM, Mikolaj Golub to.my.troc...@gmail.comwrote:

 snip
 So, I don't know what these macros actually were supposed to be. They were
 introduced in r179662:

 Revision 1.43: download - view: text, markup, annotated - select for diffs
 Mon Jun 9 01:14:10 2008 UTC (17 months, 2 weeks ago) by davidxu
 Branches: MAIN
 Diff to: previous 1.42: preferred, colored
 Changes since revision 1.42: +21 -2 lines

 SVN rev 179662 on 2008-06-09 01:14:10Z by davidxu

 Make pthread_cleanup_push() and pthread_cleanup_pop() as a pair of macros,
 use stack space to keep cleanup information, this eliminates overhead of
 calling malloc() and free() in thread library.

 Discussed on: thread@


http://lists.freebsd.org/pipermail/freebsd-threads/2008-May/004299.html

Cheers

Tom
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Kostik Belousov
On Tue, Nov 24, 2009 at 05:18:29PM +0200, Mikolaj Golub wrote:
 On Tue, 24 Nov 2009 16:53:35 +0200 Mikolaj Golub wrote:
 
  Hi,
 
  I have problems with compiling our application under 8.0.
 
  It fails due to these definitions in pthread.h that look like a typo or
  incorrectly applied patch:
 
  170 #define pthread_cleanup_push(cleanup_routine, cleanup_arg)  
  \
  171 {   
  \
  172 struct _pthread_cleanup_info 
  __cleanup_info__;  \
  173 __pthread_cleanup_push_imp(cleanup_routine, 
  cleanup_arg,\
  174 __cleanup_info__); 
  \
  175 {
  176 
  177 #define pthread_cleanup_pop(execute)
  \
  178 }   
  \
  179 __pthread_cleanup_pop_imp(execute); 
  \
  180 }
 
 
  This patch fixes the problem for me:
 
 I was hurry when said that the patch fixed the problem. The application
 compiled but later it crashed in pthread_cleanup_pop:
 
 (gdb) bt
 #0  0xbf4f9ee0 in ?? ()
 #1  0x287d18c9 in __pthread_cleanup_pop_imp () from /lib/libthr.so.3
 #2  0x287d18ed in pthread_cleanup_pop () from /lib/libthr.so.3
 #3  0x287d123c in pthread_exit () from /lib/libthr.so.3
 #4  0x287c7757 in pthread_getprio () from /lib/libthr.so.3
 #5  0x in ?? ()
 
 So, I don't know what these macros actually were supposed to be. They were
 introduced in r179662:
 
 Revision 1.43: download - view: text, markup, annotated - select for diffs
 Mon Jun 9 01:14:10 2008 UTC (17 months, 2 weeks ago) by davidxu
 Branches: MAIN
 Diff to: previous 1.42: preferred, colored
 Changes since revision 1.42: +21 -2 lines
 
 SVN rev 179662 on 2008-06-09 01:14:10Z by davidxu
 
 Make pthread_cleanup_push() and pthread_cleanup_pop() as a pair of macros,
 use stack space to keep cleanup information, this eliminates overhead of
 calling malloc() and free() in thread library.
 
 Discussed on: thread@
 
  --- pthread.h.orig2009-11-24 16:44:13.0 +0200
  +++ pthread.h   2009-11-24 16:44:45.0 +0200
  @@ -172,10 +172,10 @@
  struct _pthread_cleanup_info __cleanup_info__;  
  \
  __pthread_cleanup_push_imp(cleanup_routine, 
  cleanup_arg,\
  __cleanup_info__); 
  \
  -   {
  +   }   
   
   #definepthread_cleanup_pop(execute)
  \
  -   }   
  \
  +   {   \
  __pthread_cleanup_pop_imp(execute); 
  \
  }

pthread_cleanup_push/pop are supposed to be used from the common
lexical scope. Citation from SUSv4:

These functions may be implemented as macros. The application shall
ensure that they 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 '}' ).

Your change is wrong.

Basically, the code should do
pthread_cleanup_push(some_func, arh);
something ...
pthread_cleanup_pop(1);
(1 denotes that some_func should be called).


pgp7FToQ1ca9J.pgp
Description: PGP signature


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Hajimu UMEMOTO
Hi,

 On Tue, 24 Nov 2009 17:18:29 +0200
 Mikolaj Golub to.my.troc...@gmail.com said:

to.my.trociny I was hurry when said that the patch fixed the problem. The 
application
to.my.trociny compiled but later it crashed in pthread_cleanup_pop:

to.my.trociny (gdb) bt
to.my.trociny #0  0xbf4f9ee0 in ?? ()
to.my.trociny #1  0x287d18c9 in __pthread_cleanup_pop_imp () from 
/lib/libthr.so.3
to.my.trociny #2  0x287d18ed in pthread_cleanup_pop () from /lib/libthr.so.3
to.my.trociny #3  0x287d123c in pthread_exit () from /lib/libthr.so.3
to.my.trociny #4  0x287c7757 in pthread_getprio () from /lib/libthr.so.3
to.my.trociny #5  0x in ?? ()

to.my.trociny So, I don't know what these macros actually were supposed to be. 
They were
to.my.trociny introduced in r179662:

Your modification to pthread.h is wrong.  You need to write your code
something like following:

pthread_cleanup_push();
. . .
do something
. . .
pthread_cleanup_pop();

This is not FreeBSD alone.  pthread_cleanup_push() and
pthread_cleanup_pop() are macro on Linux as well.

Sincerely,

--
Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
u...@mahoroba.org  u...@{,jp.}FreeBSD.org
http://www.imasy.org/~ume/
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Mikolaj Golub
On Tue, 24 Nov 2009 17:34:22 +0200 Kostik Belousov wrote:

 pthread_cleanup_push/pop are supposed to be used from the common
 lexical scope. Citation from SUSv4:

 These functions may be implemented as macros. The application shall
 ensure that they 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 '}' ).

 Your change is wrong.

 Basically, the code should do
   pthread_cleanup_push(some_func, arh);
   something ...
   pthread_cleanup_pop(1);
 (1 denotes that some_func should be called).

I see. Thank you. So it really looks like a bug in our application as
pthread_cleanup_pop(1) is missed. I will tell our developers :-)

-- 
Mikolaj Golub
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Mark Andrews

Report it using send-pr.  That way the problem will make its way into the
bug tracking system.

In message 86aayc7z4g@zhuzha.ua1, Mikolaj Golub writes:
 Hi,
 
 I have problems with compiling our application under 8.0.
 
 It fails due to these definitions in pthread.h that look like a typo or
 incorrectly applied patch:
 
 170 #define pthread_cleanup_push(cleanup_routine, cleanup_arg)

\
 171 { 

\
 172 struct _pthread_cleanup_info 
 __cleanup_info__;   
\
 173 __pthread_cleanup_push_imp(cleanup_routine, 
 clean
 up_arg,\
 174 __cleanup_info__);   

\
 175 {
 176 
 177 #define pthread_cleanup_pop(execute)  

\
 178 } 

\
 179 __pthread_cleanup_pop_imp(execute);   

\
 180 }
 
 
 This patch fixes the problem for me:
 
 --- pthread.h.orig2009-11-24 16:44:13.0 +0200
 +++ pthread.h   2009-11-24 16:44:45.0 +0200
 @@ -172,10 +172,10 @@
 struct _pthread_cleanup_info __cleanup_info__;
   \
 __pthread_cleanup_push_imp(cleanup_routine, 
 cleanup_arg,\
 __cleanup_info__);   
   \
 -   {
 +   }   
  
  #definepthread_cleanup_pop(execute)  

\
 -   } 
   \
 +   {   \
 __pthread_cleanup_pop_imp(execute);   
   \
 }
 
 -- 
 Mikolaj Golub
 ___
 freebsd-stable@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-stable
 To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org
-- 
Mark Andrews, ISC
1 Seymour St., Dundas Valley, NSW 2117, Australia
PHONE: +61 2 9871 4742 INTERNET: ma...@isc.org
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Daniel Eischen

On Wed, 25 Nov 2009, Mark Andrews wrote:



Report it using send-pr.  That way the problem will make its way into the
bug tracking system.

In message 86aayc7z4g@zhuzha.ua1, Mikolaj Golub writes:

Hi,

I have problems with compiling our application under 8.0.

It fails due to these definitions in pthread.h that look like a typo or
incorrectly applied patch:


Did someone already reply to this?

I think the problem is in your application.  You cannot
have push and pop at different nesting levels.  The
start brace in the push is ended by the end brace in
pop on purpose.  It is to enforce nesting levels.



170 #define pthread_cleanup_push(cleanup_routine, cleanup_arg)
   \
171 {
   \
172 struct _pthread_cleanup_info __cleanup_info__;
   \
173 __pthread_cleanup_push_imp(cleanup_routine, 
clean
up_arg,\
174 __cleanup_info__);
   \
175 {
176
177 #define pthread_cleanup_pop(execute)
   \
178 }
   \
179 __pthread_cleanup_pop_imp(execute);
   \
180 }


--
DE
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Mark Andrews

In message 20091124153422.gt2...@deviant.kiev.zoral.com.ua, Kostik Belousov 
write
s:
 
 --i616tqyc3hrkKsk2
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Tue, Nov 24, 2009 at 05:18:29PM +0200, Mikolaj Golub wrote:
  On Tue, 24 Nov 2009 16:53:35 +0200 Mikolaj Golub wrote:
 =20
   Hi,
  
   I have problems with compiling our application under 8.0.
  
   It fails due to these definitions in pthread.h that look like a typo or
   incorrectly applied patch:
  
   170 #define pthread_cleanup_push(cleanup_routine, cleanup_a=
 rg)  \
   171 {  =
  \
   172 struct _pthread_cleanup_info __cleanup_=
 info__;  \
   173 __pthread_cleanup_push_imp(cleanup_rout=
 ine, cleanup_arg,\
   174 __cleanup_info__);=
  \
   175 {
   176=20
   177 #define pthread_cleanup_pop(execute)   =
  \
   178 }  =
  \
   179 __pthread_cleanup_pop_imp(execute);=
  \
   180 }
  
  
   This patch fixes the problem for me:
 =20
  I was hurry when said that the patch fixed the problem. The application
  compiled but later it crashed in pthread_cleanup_pop:
 =20
  (gdb) bt
  #0  0xbf4f9ee0 in ?? ()
  #1  0x287d18c9 in __pthread_cleanup_pop_imp () from /lib/libthr.so.3
  #2  0x287d18ed in pthread_cleanup_pop () from /lib/libthr.so.3
  #3  0x287d123c in pthread_exit () from /lib/libthr.so.3
  #4  0x287c7757 in pthread_getprio () from /lib/libthr.so.3
  #5  0x in ?? ()
 =20
  So, I don't know what these macros actually were supposed to be. They were
  introduced in r179662:
 =20
  Revision 1.43: download - view: text, markup, annotated - select for diffs
  Mon Jun 9 01:14:10 2008 UTC (17 months, 2 weeks ago) by davidxu
  Branches: MAIN
  Diff to: previous 1.42: preferred, colored
  Changes since revision 1.42: +21 -2 lines
 =20
  SVN rev 179662 on 2008-06-09 01:14:10Z by davidxu
 =20
  Make pthread_cleanup_push() and pthread_cleanup_pop() as a pair of macros,
  use stack space to keep cleanup information, this eliminates overhead of
  calling malloc() and free() in thread library.
 =20
  Discussed on: thread@
 =20
   --- pthread.h.orig2009-11-24 16:44:13.0 +0200
   +++ pthread.h   2009-11-24 16:44:45.0 +0200
   @@ -172,10 +172,10 @@
   struct _pthread_cleanup_info __cleanup_info__; =
  \
   __pthread_cleanup_push_imp(cleanup_routine, cle=
 anup_arg,\
   __cleanup_info__);=
  \
   -   {
   +   }  =20
   =20
#definepthread_cleanup_pop(execute)   =
  \
   -   }  =
  \
   +   {  =
  \
   __pthread_cleanup_pop_imp(execute);=
  \
   }
 
 pthread_cleanup_push/pop are supposed to be used from the common
 lexical scope. Citation from SUSv4:
 
 These functions may be implemented as macros. The application shall
 ensure that they 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 '}' ).
 
 Your change is wrong.
 
 Basically, the code should do
   pthread_cleanup_push(some_func, arh);
   something ...
   pthread_cleanup_pop(1);
 (1 denotes that some_func should be called).

The problem is that that expands to C code that can only be used
with newer C compilers.  This expansion should be usable with all
C compilers.

#define pthread_cleanup_push(cleanup_routine, cleanup_arg) \
{  \
struct _pthread_cleanup_info __cleanup_info__; \
__pthread_cleanup_push_imp(cleanup_routine, cleanup 
_arg,\
   __cleanup_info__)

#define pthread_cleanup_pop(execute)   \
   __pthread_cleanup_pop_imp(execute);\
} ((void)0)

 
 --i616tqyc3hrkKsk2
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.10 (FreeBSD)
 
 

Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Daniel Eischen

On Wed, 25 Nov 2009, Mark Andrews wrote:



In message 20091124153422.gt2...@deviant.kiev.zoral.com.ua, Kostik Belousov 
write
s:


--i616tqyc3hrkKsk2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Nov 24, 2009 at 05:18:29PM +0200, Mikolaj Golub wrote:

pthread_cleanup_push/pop are supposed to be used from the common
lexical scope. Citation from SUSv4:

These functions may be implemented as macros. The application shall
ensure that they 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 '}' ).

Your change is wrong.

Basically, the code should do
pthread_cleanup_push(some_func, arh);
something ...
pthread_cleanup_pop(1);
(1 denotes that some_func should be called).


The problem is that that expands to C code that can only be used
with newer C compilers.  This expansion should be usable with all
C compilers.

#define pthread_cleanup_push(cleanup_routine, cleanup_arg) \
{  \
struct _pthread_cleanup_info __cleanup_info__; \
   __pthread_cleanup_push_imp(cleanup_routine, cleanup 
_arg,\
   __cleanup_info__)

#define pthread_cleanup_pop(execute)   \
  __pthread_cleanup_pop_imp(execute);\
   } ((void)0)


Hmm, agreed.  But note that Solaris 10 does it this way:

#define pthread_cleanup_push(routine, args) { \
_cleanup_t _cleanup_info; \
__pthread_cleanup_push((_Voidfp)(routine), (void *)(args), \
(caddr_t)_getfp(), _cleanup_info);

#define pthread_cleanup_pop(ex) \
__pthread_cleanup_pop(ex, _cleanup_info); \
}

--
DE
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread Mark Andrews

In message pine.gso.4.64.0911241718490.5...@sea.ntplx.net, Daniel Eischen wri
tes:
 On Wed, 25 Nov 2009, Mark Andrews wrote:
 
 
  In message 20091124153422.gt2...@deviant.kiev.zoral.com.ua, Kostik Belous
 ov write
  s:
 
  --i616tqyc3hrkKsk2
  Content-Type: text/plain; charset=us-ascii
  Content-Disposition: inline
  Content-Transfer-Encoding: quoted-printable
 
  On Tue, Nov 24, 2009 at 05:18:29PM +0200, Mikolaj Golub wrote:
 
  pthread_cleanup_push/pop are supposed to be used from the common
  lexical scope. Citation from SUSv4:
 
  These functions may be implemented as macros. The application shall
  ensure that they 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 '}' ).
 
  Your change is wrong.
 
  Basically, the code should do
 pthread_cleanup_push(some_func, arh);
 something ...
 pthread_cleanup_pop(1);
  (1 denotes that some_func should be called).
 
  The problem is that that expands to C code that can only be used
  with newer C compilers.  This expansion should be usable with all
  C compilers.
 
  #define pthread_cleanup_push(cleanup_routine, cleanup_arg) 
 \
  {  \
  struct _pthread_cleanup_info __cleanup_info__; \
 __pthread_cleanup_push_imp(cleanup_routine, cleanup 
 _arg,\
 __cleanup_info__)
 
  #define pthread_cleanup_pop(execute)   
 \
__pthread_cleanup_pop_imp(execute);\
 } ((void)0)
 
 Hmm, agreed.  But note that Solaris 10 does it this way:
 
 #define   pthread_cleanup_push(routine, args) { \
   _cleanup_t _cleanup_info; \
   __pthread_cleanup_push((_Voidfp)(routine), (void *)(args), \
   (caddr_t)_getfp(), _cleanup_info);
 
 #define   pthread_cleanup_pop(ex) \
   __pthread_cleanup_pop(ex, _cleanup_info); \
 }

Writing portable macros that don't generate compiler warnings is fun. :-)

Tricks like do { body } while (0) and  { body } ((void)0) absorb
the pesky semi-colon.
 
 -- 
 DE
-- 
Mark Andrews, ISC
1 Seymour St., Dundas Valley, NSW 2117, Australia
PHONE: +61 2 9871 4742 INTERNET: ma...@isc.org
___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org


Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop

2009-11-24 Thread David Xu

Daniel Eischen wrote:


Hmm, agreed.  But note that Solaris 10 does it this way:

#definepthread_cleanup_push(routine, args) { \
_cleanup_t _cleanup_info; \
__pthread_cleanup_push((_Voidfp)(routine), (void *)(args), \
(caddr_t)_getfp(), _cleanup_info);

#definepthread_cleanup_pop(ex) \
__pthread_cleanup_pop(ex, _cleanup_info); \
}



Hmm, I considered using this style, but if there is a C++ object within 
the lexical scope, its destructor will execute after

pthread_cleanup_pop(), this may not be correct, so I used extra pair of
'{}'.

___
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to freebsd-stable-unsubscr...@freebsd.org