Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linux-dvb] Re: More V4 Video API Q's








Holger Waechtler <holger@qanu.de> wrote on 10/10/2004 12:02:05:

> Rob.McConnell@Zarlink.Com wrote:
>
> >
> >Now the question is should the corresponding pthread_cleanup_pop be
placed
> >at the same level as the push or at a higher level to ensure the cleanup
> >handler is removed properly.
> >
> >e.g.  pthread_cleanup_push(cleanup_handler, NULL);
> >
> >      ioctl(DVB_VIDEO_GET_EVENT, ......);      [BLOCKED]
> >
> >      pthread_cleanup_pop(0);
> >
> >Here if another thread/process calls pthread_cancel to cancel this
thread,
> >then it will exit immediately before it gets to pthread_cleanup_pop.
The
> >man page recommends keeping the push/pop calls in the same function, but
> >I'm not convinced of this.
> >
> >Any comments?
> >
> >
>
> Maybe you want to take a look into the push/pop() declaration and
> implementation: they are macros and start a new {}-block:
>
> -------------------- /usr/include/pthread.h ------------------------
>
> /* Install a cleanup handler: ROUTINE will be called with arguments ARG
>    when the thread is cancelled or calls pthread_exit.  ROUTINE will also
>    be called with arguments ARG when the matching pthread_cleanup_pop
>    is executed with non-zero EXECUTE argument.
>    pthread_cleanup_push and pthread_cleanup_pop are macros and must
always
>    be used in matching pairs at the same nesting level of braces. */
>
> #define pthread_cleanup_push(routine,arg) \
>   { struct _pthread_cleanup_buffer
> _buffer;                                   \
>     _pthread_cleanup_push (&_buffer, (routine), (arg));
>
> extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer
*__buffer,
>                                    void (*__routine) (void *),
>                                    void *__arg) __THROW;
>
> /* Remove a cleanup handler installed by the matching
pthread_cleanup_push.
>    If EXECUTE is non-zero, the handler function is called. */
>
> #define pthread_cleanup_pop(execute) \
>     _pthread_cleanup_pop (&_buffer, (execute)); }
>
> extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer
*__buffer,
>                                   int __execute) __THROW;
>
> -----------------------------
>
> So they definitely need to live in the same function.

Thanks, that sums things up nicely. I should look at the source code more
often. ;^)

Rob : )





Home | Main Index | Thread Index