On 10/22/26 11:37, Peter Maydell wrote:
In do_fork() and clone_func() we currently use a pthread_mutex_t and
a pthread_cond_t to allow the parent thread to wait until the child
thread has started and e.g.  set fields like info->tid, before the
parent reads those fields and otherwise proceeds.

Coverity points out that this use of a pthread condition variable
isn't reliable: pthread_cond_wait() may wake up spuriously, so the
idiom for "wait on a condition" should be "loop around calling
pthread_cond_wait() until a predicate that was updated by the caller
of pthread_cond_broadcast() is true".

This is quite old code; rather than fixing up its use of raw pthread
condition variables, we can use a QemuSemaphore.  This gives us the
"thread A waits until thread B signals it" semantics we want.  (Under
the hood it is implemented with a mutex and condition variable.)

Cc:[email protected]
Resolves: CID 1527417
Signed-off-by: Peter Maydell<[email protected]>
---
cc stable because in theory this could result in the parent thread
waking up too early and weird stuff happening; however my guess is
that in practice with one waiter and one signaller that the
"spurious wakeup" case won't happen. At any rate this code has
been like this for a very long time.

Disclaimer: tested with "make check" only, but that does include
various linux-user tests that use multiple threads.
---
  linux-user/syscall.c | 17 +++++------------
  1 file changed, 5 insertions(+), 12 deletions(-)

Reviewed-by: Richard Henderson <[email protected]>

r~

Reply via email to