[vlc-devel] [PATCH] Deprecate vlc_clone_detach()

Alexandre Janniaux ajanni at videolabs.io
Mon Sep 7 11:48:29 CEST 2020


Hi,

I'm fine with this patchset.

If we need this function to be implemented safely, we can probably
do the same as posix synchronization primitives and implement the
detach ourself with some intricated ways and smart resource deletion
but it looks more like a maintenance burden with sharp edges.

In general, I prefer a joined thread which require a more structural
approach to the issues mentionned by Romain, making it a bit less easy
to write, but also a bit easier to follow and less resource-management
error prone.

There's a typo in the commit message though, «functon».

Regards,
--
Alexandre Janniaux
Videolabs

On Sun, Sep 06, 2020 at 03:32:27PM +0300, Rémi Denis-Courmont wrote:
> The documention outright lies about LibVLC waiting to make this functon
> safe. There are no ways to use this function safely other than linking
> LibVLC statically into the application, which is not *generally*
> practical.
> ---
>  src/libvlc.h       |  2 +-
>  src/posix/thread.c | 23 +++++++----------------
>  2 files changed, 8 insertions(+), 17 deletions(-)
>
> diff --git a/src/libvlc.h b/src/libvlc.h
> index d2d112aa56..884af326a3 100644
> --- a/src/libvlc.h
> +++ b/src/libvlc.h
> @@ -44,7 +44,7 @@ void vlc_CPU_dump(vlc_object_t *);
>   * Threads subsystem
>   */
>
> -/* This cannot be used as is from plugins yet: */
> +VLC_DEPRECATED
>  int vlc_clone_detach (vlc_thread_t *, void *(*)(void *), void *, int);
>
>  int vlc_set_priority( vlc_thread_t, int );
> diff --git a/src/posix/thread.c b/src/posix/thread.c
> index d8edc13d53..33f6da47bc 100644
> --- a/src/posix/thread.c
> +++ b/src/posix/thread.c
> @@ -229,27 +229,18 @@ void vlc_join(vlc_thread_t th, void **result)
>
>  /**
>   * Creates and starts new detached thread.
> + *
>   * A detached thread cannot be joined. Its resources will be automatically
>   * released whenever the thread exits (in particular, its call stack will be
>   * reclaimed).
>   *
> - * Detached thread are particularly useful when some work needs to be done
> - * asynchronously, that is likely to be completed much earlier than the thread
> - * can practically be joined. In this case, thread detach can spare memory.
> - *
> - * A detached thread may be cancelled, so as to expedite its termination.
> - * Be extremely careful if you do this: while a normal joinable thread can
> - * safely be cancelled after it has already exited, cancelling an already
> - * exited detached thread is undefined: The thread handle would is destroyed
> - * immediately when the detached thread exits. So you need to ensure that the
> - * detached thread is still running before cancellation is attempted.
> - *
> - * @warning Care must be taken that any resources used by the detached thread
> - * remains valid until the thread completes.
> + * \warning
> + * Detached thread are intrinsically unsafe to use, as there are no ways to
> + * know whence the thread has terminated cleanly and its resources can be
> + * reclaimed (in particular, the executable code run by the thread).
>   *
> - * @note A detached thread must eventually exit just like another other
> - * thread. In practice, LibVLC will wait for detached threads to exit before
> - * it unloads the plugins.
> + * \bug
> + * This function should be removed. Do not use this function in new code.
>   *
>   * @param th [OUT] pointer to hold the thread handle, or NULL
>   * @param entry entry point for the thread
> --
> 2.28.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list