<div dir="ltr">Classic API Barriers offer a cleaner alternative to using semaphore_flush. Unlike <div>POSIX barriers, they have a manual release option. And unlike semaphore_flush,</div><div>you wake up with SUCCESSFUL when it is signaled/released. It seems more</div><div>natural to get an OK than an UNSATISFIED when you got the "good result".</div><div><br></div><div>Off the top of my head, I don't know if they address the scenario you are</div><div>warning about but it would be nice to address the same use case and possibly</div><div>same issue.</div><div><br></div><div>--joel<br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 17, 2017 at 12:30 AM, Sebastian Huber <span dir="ltr"><<a href="mailto:sebh@rtems.org" target="_blank">sebh@rtems.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Module:    rtems-docs<br>
Branch:    master<br>
Commit:    d9ecff105d5438158a994f106ca7f5<wbr>5b5c4e60e3<br>
Changeset: <a href="http://git.rtems.org/rtems-docs/commit/?id=d9ecff105d5438158a994f106ca7f55b5c4e60e3" rel="noreferrer" target="_blank">http://git.rtems.org/rtems-<wbr>docs/commit/?id=<wbr>d9ecff105d5438158a994f106ca7f5<wbr>5b5c4e60e3</a><br>
<br>
Author:    Sebastian Huber <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-<wbr>brains.de</a>><br>
Date:      Thu Nov 16 10:29:43 2017 +0100<br>
<br>
c-users: Clarify semaphore obtain/flush<br>
<br>
---<br>
<br>
 c-user/semaphore_manager.rst | 44 ++++++++++++++++++++++++++++++<wbr>+++++++++++++-<br>
 1 file changed, 43 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/c-user/semaphore_manager.rst b/c-user/semaphore_manager.rst<br>
index 27080e0..f39f429 100644<br>
--- a/c-user/semaphore_manager.rst<br>
+++ b/c-user/semaphore_manager.rst<br>
@@ -614,6 +614,11 @@ DESCRIPTION:<br>
     semaphore is available or the ``RTEMS_NO_WAIT`` option component is set,<br>
     then timeout is ignored.<br>
<br>
+    In case a semaphore is not available, then ``RTEMS_UNSATISFIED`` will be<br>
+    returned.  This happens immediately in case ``RTEMS_NO_WAIT`` is specified,<br>
+    or as a result of another task invoking the ``rtems_semaphore_flush``<br>
+    directive in case ``RTEMS_WAIT`` is specified.<br>
+<br>
     Deadlock situations are detected for MrsP semaphores and the<br>
     ``RTEMS_UNSATISFIED`` status code will be returned in SMP configurations in<br>
     this case.<br>
@@ -734,7 +739,7 @@ DIRECTIVE STATUS CODES:<br>
      * - ``RTEMS_INVALID_ID``<br>
        - invalid semaphore id<br>
      * - ``RTEMS_NOT_DEFINED``<br>
-       - operation not defined for the protocol ofthe semaphore<br>
+       - operation not defined for the protocol of the semaphore<br>
      * - ``RTEMS_ILLEGAL_ON_REMOTE_<wbr>OBJECT``<br>
        - not supported for remote semaphores<br>
<br>
@@ -762,6 +767,43 @@ NOTES:<br>
     It is not allowed to flush a MrsP semaphore and the ``RTEMS_NOT_DEFINED``<br>
     status code will be returned in SMP configurations in this case.<br>
<br>
+    Using the ``rtems_semaphore_flush`` directive for condition synchronization<br>
+    in concert with another semaphore may be subject to the lost wake-up<br>
+    problem.  The following attempt to implement a condition variable is<br>
+    broken.<br>
+<br>
+    .. code-block:: c<br>
+<br>
+        #include <rtems.h><br>
+        #include <assert.h><br>
+<br>
+        void cnd_wait( rtems_id cnd, rtems_id mtx )<br>
+        {<br>
+          rtems_status_code sc;<br>
+<br>
+          sc = rtems_semaphore_release( mtx );<br>
+          assert( sc == RTEMS_SUCCESSFUL );<br>
+<br>
+          /*<br>
+           * Here, a higher priority task may run and satisfy the condition. We<br>
+           * may never wake up from the next semaphore obtain.<br>
+           */<br>
+<br>
+          sc = rtems_semaphore_obtain( cnd, RTEMS_WAIT, RTEMS_NO_TIMEOUT );<br>
+          assert( sc == RTEMS_UNSATISFIED );<br>
+<br>
+          sc = rtems_semaphore_obtain( mtx, RTEMS_WAIT, RTEMS_NO_TIMEOUT );<br>
+          assert( sc == RTEMS_SUCCESSFUL );<br>
+        }<br>
+<br>
+        void cnd_broadcast( rtems_id cnd )<br>
+        {<br>
+          rtems_status_code sc;<br>
+<br>
+          sc = rtems_semaphore_flush( cnd );<br>
+          assert( sc == RTEMS_SUCCESSFUL );<br>
+        }<br>
+<br>
 .. raw:: latex<br>
<br>
    \clearpage<br>
<br>
______________________________<wbr>_________________<br>
vc mailing list<br>
<a href="mailto:vc@rtems.org">vc@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/vc" rel="noreferrer" target="_blank">http://lists.rtems.org/<wbr>mailman/listinfo/vc</a><br>
</blockquote></div><br></div></div></div>