Subject: lib/31320: pthread_cleanup_push and pthread_cleanup_pop macros broken
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <netbsd@wolfnode.de>
List: netbsd-bugs
Date: 09/15/2005 09:22:00
>Number:         31320
>Category:       lib
>Synopsis:       pthread_cleanup_push and pthread_cleanup_pop macros broken
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 15 09:22:00 +0000 2005
>Originator:     Florian Stoehr
>Release:        current
>Organization:
>Environment:
>Description:
pthread_cleanup_push and pthread_cleanup_pop are macros from pthread.h.

They are currentely implemented as:

#define pthread_cleanup_push(routine, arg)			\
        {							\
		struct pthread_cleanup_store __store;		\
		pthread__cleanup_push((routine),(arg), &__store);

#define pthread_cleanup_pop(execute)				\
		pthread__cleanup_pop((execute), &__store);	\
	}


I think the closing bracket from pop must move to push...
>How-To-Repeat:
void test(void* P)
{
    // Shutdown handler
}

void* threadMain(void* P)
{
    // This will *NOT* work...
    pthread_cleanup_push(test, P);

    // But this DOES work - which is wrong
    pthread_cleanup_push(test, P) }  // Yes, }
}
>Fix:
Replace the macros by

#define pthread_cleanup_push(routine, arg)			\
        {							\
		struct pthread_cleanup_store __store;		\
		pthread__cleanup_push((routine),(arg), &__store); \
        }

#define pthread_cleanup_pop(execute)				\
		pthread__cleanup_pop((execute), &__store);