________________________________________________________________________
Applicable Environment
________________________________________________________________________
- Topic: sem_timedwait() behavior difference on named and unnamed semaphores
- SDP: 6.5.0
- Target: Any supported target
________________________________________________________________________
Solution________________________________________________________________________
There is a difference between the behavior of named (created with
sem_init) and unnamed (created/accessed with sem_open) semaphores in
QNX. This is true in the OS versions up to and including 6.5.0.
The difference is in the value of the errno setting upon an
unsuccessful return from a sem_timedwait() function call. When
returning from this call after a timeout has been hit the following
errno values are set:
Unnamed Semaphore (sem_init created) : errno=ETIMEDOUT
Named Semaphore (sem_open created) : errno=EINTR
This behavior is due to the way named semaphores are handled in
QNX. To use named semaphores requires that a separate named-semaphore
manger is running. Unnamed semaphores are implemented as kernel
primitives.
In the case of named semaphores, a client transaction takes
place on top of standard message-passing and the unblock pulse used in
this case cannot contain sufficient information. The lack of
information to the unblock request sent to the server results in an
inability to correctly signal the client for either EINTR or ETIMEDOUT.
For this reason a compromise was made and EINTR is returned.
The workaround suggested and used currently is to understand
this difference in behavior and implement code that takes this behavior
into account. An alternative is to avoid named semaphores and only use
the unnamed variant which does not make use of the intermediate manager
mqueue.
A resolution to this difference in behavior may be addressed in a future OS release. Reference number 18966.