pthread_cleanup_push & pthread_cleanup_pop usage

John Hein jhein at timing.com
Wed Oct 8 04:45:25 UTC 2008


In June pthread_cleanup_push & pthread_cleanup_pop were changed to macros
that look like so...

+#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);                     \
+               }
+


This breaks code where the pop is done in an inner block level.

simplified example:

    pthread_cleanup_push(docleanup, &foo);
    try
    {   
        dostuff();
    }
    catch (...)
    {   
        pthread_cleanup_pop(1);
        throw;
    }
    pthread_cleanup_pop(1);

Does anyone have a recommended fix?


More information about the freebsd-threads mailing list