Posix skin and Mutex initialisation/destruction inconsistencies

Lange Norbert norbert.lange at andritz.com
Wed Mar 6 10:39:48 CET 2019


There is an inconsistency with the documentation [1], which claims that mutex and condition variables
need to be explicitly initialized with the *_init functions.
The implementation however checks the state via a flag and calls *_init if necessary, and the program below works correctly.

There is some further issue, if you depend on the "lazy initialization", demonstrated by running the
program below with an argument. This case can happen for example if some subsystem was removed
before being used (never needed the lock).
In other words, the "lazy initialization" scheme is working with lock/unlock but not with destroy.

#include <assert.h>
#include <pthread.h>

int main(int argc, char const *argv[]) {
        pthread_mutex_t mymutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;

  if (argc == 1) {
    assert(0 == pthread_mutex_lock(&mymutex));
    assert(0 == pthread_mutex_unlock(&mymutex));
  assert(0 == pthread_mutex_destroy(&mymutex));

  return 0;

[1] - https://gitlab.denx.de/Xenomai/xenomai/wikis/Porting_To_Xenomai_POSIX

Regards, Norbert

This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.


Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation

Firmensitz/ Registered seat: Wien

Firmenbuchgericht/ Court of registry: Handelsgericht Wien

Firmenbuchnummer/ Company registration: FN 61833 g

DVR: 0605077

UID-Nr.: ATU14756806

Thank You

More information about the Xenomai mailing list