All of lore.kernel.org
 help / color / mirror / Atom feed
* Posix skin and Mutex initialisation/destruction inconsistencies
@ 2019-03-06  9:39 Lange Norbert
  2019-03-06 17:35 ` Jan Kiszka
  0 siblings, 1 reply; 2+ messages in thread
From: Lange Norbert @ 2019-03-06  9:39 UTC (permalink / raw)
  To: Xenomai (xenomai@xenomai.org)

Hello,

1)
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.

2)
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.

ANDRITZ HYDRO GmbH


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
________________________________


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Posix skin and Mutex initialisation/destruction inconsistencies
  2019-03-06  9:39 Posix skin and Mutex initialisation/destruction inconsistencies Lange Norbert
@ 2019-03-06 17:35 ` Jan Kiszka
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kiszka @ 2019-03-06 17:35 UTC (permalink / raw)
  To: Lange Norbert, Xenomai (xenomai@xenomai.org)

On 06.03.19 10:39, Lange Norbert via Xenomai wrote:
> Hello,
> 
> 1)
> 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.

Lazy init is not a recommended pattern as it implies high costs and potentially 
unexpected (and often unhandled) errors for typically critical lock/unlock 
operations. I would guess that this is why it was not explicitly mentioned.

> 
> 2)
> 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));

That should probably be fixed. Patch welcome.

Jan

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-06 17:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-06  9:39 Posix skin and Mutex initialisation/destruction inconsistencies Lange Norbert
2019-03-06 17:35 ` Jan Kiszka

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.