Skip to content
  • Gilles Chanteperdrix's avatar
    posix/mutex: fix autoinit · dfa9ad71
    Gilles Chanteperdrix authored
    If several threads call simultaneously pthread_mutex_lock() on a mutex
    initialized with PTHREAD_MUTEX_INITIALIZER, the current automatic
    intialization may result in several initializations of the mutex.
    Serialize the automatic initialization with a global mutex to avoid
    that.
    
    This can be done only for automatic initialization, as
    pthread_mutex_init() may be called from a non Xenomai thread, which
    could not sleep on a cobalt mutex, and serializing with a plain Linux
    mutex would cause a switch to secondary mode for pthread_mutex_lock() in
    case of automatic initialization.
    
    Using a condition variable would create a cancellation point, whereas
    pthread_mutex_lock() and pthread_mutex_unlock() can not be cancellation
    points.
    dfa9ad71