Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Nov 2009 17:20:25 -0500 (EST)
From:      Daniel Eischen <deischen@freebsd.org>
To:        Mark Andrews <marka@isc.org>
Cc:        Kostik Belousov <kostikbel@gmail.com>, FreeBSD Stable <freebsd-stable@freebsd.org>, Mikolaj Golub <to.my.trociny@gmail.com>
Subject:   Re: pthread.h: typo in #define	pthread_cleanup_push/pthread_cleanup_pop
Message-ID:  <Pine.GSO.4.64.0911241718490.5810@sea.ntplx.net>
In-Reply-To: <200911242141.nAOLfAQa050429@drugs.dv.isc.org>
References:  <86aayc7z4g.fsf@zhuzha.ua1> <8663907xyy.fsf@zhuzha.ua1> <20091124153422.GT2331@deviant.kiev.zoral.com.ua> <200911242141.nAOLfAQa050429@drugs.dv.isc.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 25 Nov 2009, Mark Andrews wrote:

>
> In message <20091124153422.GT2331@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.0911241718490.5810>