All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Juraj Marcin <jmarcin@redhat.com>
Cc: qemu-devel@nongnu.org, Jiri Denemark <jdenemar@redhat.com>,
	Stefan Weil <sw@weilnetz.de>, Paolo Bonzini <pbonzini@redhat.com>,
	Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>
Subject: Re: [RFC PATCH 1/4] qemu-thread: Introduce qemu_thread_detach()
Date: Tue, 19 Aug 2025 11:37:42 +0100	[thread overview]
Message-ID: <aKRT9lOS6QkRqlWA@redhat.com> (raw)
In-Reply-To: <20250807114922.1013286-2-jmarcin@redhat.com>

On Thu, Aug 07, 2025 at 01:49:09PM +0200, Juraj Marcin wrote:
> From: Juraj Marcin <jmarcin@redhat.com>
> 
> Currently, QEMU threads abstraction supports both joinable and detached
> threads, but once a thread is marked as joinable it must be joined using
> qemu_thread_join() and cannot be detached later.

IMHO it is a good thing to avoid the concept of turning a joinable
thread into a detached thread at runtime. Such a change makes it
harder to reason about the correctness of the code, as you need to
fully understand the global picture of what code runs at each
phase of the thread's life, to decide if you need to join or not.
So I'd really encourage looking at whether the migration code can
be made to *always* join, rather than mixing joinable/detached for
the same thread.

> 
> For POSIX implementation, pthread_detach() is used. For Windows, marking
> the thread as detached and releasing critical section is enough as
> thread handle is released by qemu_thread_create().
> 
> Signed-off-by: Juraj Marcin <jmarcin@redhat.com>
> ---
>  include/qemu/thread.h    |  1 +
>  util/qemu-thread-posix.c |  8 ++++++++
>  util/qemu-thread-win32.c | 10 ++++++++++
>  3 files changed, 19 insertions(+)
> 
> diff --git a/include/qemu/thread.h b/include/qemu/thread.h
> index f0302ed01f..8a6d1ba98e 100644
> --- a/include/qemu/thread.h
> +++ b/include/qemu/thread.h
> @@ -212,6 +212,7 @@ int qemu_thread_set_affinity(QemuThread *thread, unsigned long *host_cpus,
>  int qemu_thread_get_affinity(QemuThread *thread, unsigned long **host_cpus,
>                               unsigned long *nbits);
>  void *qemu_thread_join(QemuThread *thread);
> +void qemu_thread_detach(QemuThread *thread);
>  void qemu_thread_get_self(QemuThread *thread);
>  bool qemu_thread_is_self(QemuThread *thread);
>  G_NORETURN void qemu_thread_exit(void *retval);
> diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> index ba725444ba..20442456b5 100644
> --- a/util/qemu-thread-posix.c
> +++ b/util/qemu-thread-posix.c
> @@ -536,3 +536,11 @@ void *qemu_thread_join(QemuThread *thread)
>      }
>      return ret;
>  }
> +
> +void qemu_thread_detach(QemuThread *thread)
> +{
> +    int err = pthread_detach(thread->thread);
> +    if (err) {
> +        error_exit(err, __func__);
> +    }
> +}
> diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
> index ca2e0b512e..bdfb7b4aee 100644
> --- a/util/qemu-thread-win32.c
> +++ b/util/qemu-thread-win32.c
> @@ -328,6 +328,16 @@ void *qemu_thread_join(QemuThread *thread)
>      return ret;
>  }
>  
> +void qemu_thread_detach(QemuThread *thread)
> +{
> +    QemuThreadData *data;
> +
> +    if (data->mode == QEMU_THREAD_JOINABLE) {
> +        data->mode = QEMU_THREAD_DETACHED;
> +        DeleteCriticalSection(&data->cs);
> +    }
> +}
> +
>  static bool set_thread_description(HANDLE h, const char *name)
>  {
>      HRESULT hr;
> -- 
> 2.50.1
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2025-08-19 10:38 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-07 11:49 [RFC PATCH 0/4] migration: Introduce postcopy-setup capability and state Juraj Marcin
2025-08-07 11:49 ` [RFC PATCH 1/4] qemu-thread: Introduce qemu_thread_detach() Juraj Marcin
2025-08-19 10:37   ` Daniel P. Berrangé [this message]
2025-08-07 11:49 ` [RFC PATCH 2/4] migration: Fix state transition in postcopy_start() error handling Juraj Marcin
2025-08-07 20:54   ` Peter Xu
2025-08-08  9:44     ` Juraj Marcin
2025-08-08 16:00       ` Peter Xu
2025-08-08 19:08     ` Fabiano Rosas
2025-08-11 13:00       ` Juraj Marcin
2025-08-07 11:49 ` [RFC PATCH 3/4] migration: Make listen thread joinable Juraj Marcin
2025-08-07 20:57   ` Peter Xu
2025-08-08 11:08     ` Juraj Marcin
2025-08-08 17:05       ` Peter Xu
2025-08-11 13:02         ` Juraj Marcin
2025-08-07 11:49 ` [RFC PATCH 4/4] migration: Introduce postcopy-setup capability and state Juraj Marcin
2025-08-11 14:54 ` [RFC PATCH 0/4] " Peter Xu
2025-08-12 13:34   ` Juraj Marcin
2025-08-13 17:42     ` Peter Xu
2025-08-14 15:42       ` Juraj Marcin
2025-08-14 19:24         ` Peter Xu
2025-08-15  6:35           ` Juraj Marcin
2025-09-01 17:57           ` Dr. David Alan Gilbert
2025-09-02  8:30             ` Juraj Marcin
2025-09-03 12:00               ` Dr. David Alan Gilbert
2025-09-03 13:07                 ` Peter Xu
2025-09-04 16:11                 ` Juraj Marcin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aKRT9lOS6QkRqlWA@redhat.com \
    --to=berrange@redhat.com \
    --cc=farosas@suse.de \
    --cc=jdenemar@redhat.com \
    --cc=jmarcin@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.