Skip to content
  • Paolo Bonzini's avatar
    24fa9049
    qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK · 24fa9049
    Paolo Bonzini authored
    
    
    PTHREAD_MUTEX_ERRORCHECK is completely broken with respect to fork.
    The way to safely do fork is to bring all threads to a quiescent
    state by acquiring locks (either in callers---as we do for the
    iothread mutex---or using pthread_atfork's prepare callbacks)
    and then release them in the child.
    
    The problem is that releasing error-checking locks in the child
    fails under glibc with EPERM, because the mutex stores a different
    owner tid than the duplicated thread in the child process.  We
    could make it work for locks acquired via pthread_atfork, by
    recreating the mutex in the child instead of unlocking it
    (we know that there are no other threads that could have taken
    the mutex; but when the lock is acquired in fork's caller
    that would not be possible.
    
    The simplest solution is just to forgo error checking.
    
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    24fa9049
    qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK
    Paolo Bonzini authored
    
    
    PTHREAD_MUTEX_ERRORCHECK is completely broken with respect to fork.
    The way to safely do fork is to bring all threads to a quiescent
    state by acquiring locks (either in callers---as we do for the
    iothread mutex---or using pthread_atfork's prepare callbacks)
    and then release them in the child.
    
    The problem is that releasing error-checking locks in the child
    fails under glibc with EPERM, because the mutex stores a different
    owner tid than the duplicated thread in the child process.  We
    could make it work for locks acquired via pthread_atfork, by
    recreating the mutex in the child instead of unlocking it
    (we know that there are no other threads that could have taken
    the mutex; but when the lock is acquired in fork's caller
    that would not be possible.
    
    The simplest solution is just to forgo error checking.
    
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Loading