<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    I would like to use boost::atomic< T> or std::atomic< T>
    but unfortunately boost and c++11 are unavailable to me. I agree
    that std::atomic< T> or the like would be the best way to go
    though.<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 03/18/2015 12:16 AM, Jeff Shanab
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAM09syqO+4+JdFBA3MtAMby3UV=XQ7YeMXa8JiLyce3G5J+1MA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>I have used boost atomic or just a boost mutex with a
          scoped_lock when I needed to protect, It implements cross
          platform the best avail on a platform. <br>
          <br>
        </div>
        <div><br>
          <br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Tue, Mar 17, 2015 at 9:07 AM, Robert
          Smith <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:smith@cognitec.com" target="_blank">smith@cognitec.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000"> Ok, I will implement
              my own TaskScheduler class, but operations that
              read-modify-write memory are not atomic with multiple
              processors/cores. I guess the large portion of users these
              days will be using multicore x86 processors.<br>
              <br>
              I asked this question on stackoverflow and the responses
              support the research I have done myself.<br>
              <br>
              <a moz-do-not-send="true"
href="http://stackoverflow.com/questions/29099094/is-the-c-operator-atomic-with-a-multicore-processor"
                target="_blank">http://stackoverflow.com/questions/29099094/is-the-c-operator-atomic-with-a-multicore-processor</a><br>
              <br>
              My updated  application with a protected triggerEvent()
              method didn't cure the problem, one (out of six) of the
              streams stopped after an hour. I then modified
              BasicTaskScheduler to protect all reads/writes of the
              fTriggersAwaitingHandling and it has been running for over
              24 hours now. Time will tell but it looks promising.<br>
              <br>
              If I'm to speculate why this hasn't been a problem before
              I would guess that the large majority of users are not
              using the triggers at runtime, e.g, they are using the
              file sources. And for those who are using a live source,
              if they only have one stream then the task schedulers'
              SingleStep() method is probably waiting in the select()
              call when the triggerEvent() method is called making it
              unlikely that they conflict.<br>
              <br>
              Also each thread in my application has it's own event
              trigger id.<br>
              <br>
              I'm not even suggesting that you change the implementation
              but at least be aware of the problem and document it for
              future users.<br>
              <br>
              <br>
              <div>On 03/16/2015 05:50 PM, Ross Finlayson wrote:<br>
              </div>
              <blockquote type="cite">
                <div>
                  <blockquote type="cite">
                    <div>
                      <div bgcolor="#FFFFFF" text="#000000">Having
                        thought about it some more, I don't think it's
                        enough to just protect calls to triggerEvent()
                        because 'fTriggersAwaitingHandling' is still
                        modified by BasicTaskScheduler::SingleStep().<br>
                      </div>
                    </div>
                  </blockquote>
                  <div><br>
                  </div>
                  The intention of the code that implements
                  “BasicTaskScheduler” was that:</div>
                <div>1/ The event loop code (which is always just a
                  single thread, remember) does nothing with
                  “fTriggersAwaitingHandling” except clear (using
                  “&=~”) a single bit that was already set, and</div>
                <div>2/ The other thread(s) that can trigger event(s) do
                  nothing with “fTriggersAwaitingHandling” except set
                  (using “|=“) bit(s) that were not already set.</div>
                <div><br>
                </div>
                <div>If these two conditions are met, *and* if the
                  ‘clear a bit’ and ‘set a bit’ operations are atomic,
                  then the code will be thread-safe.</div>
                <div><br>
                </div>
                <div>(If, OTOH, you’re worried that the ‘clear a bit’
                  and ‘set a bit’ operations might not be atomic on your
                  system, then you’d need to write your own
                  “TaskScheduler” subclass instead.)</div>
                <div><br>
                </div>
                <div>Looking at the code again just now, however, I
                  realized that the event loop code does not always
                  satisfy condition 1/.   Line 183 of
                  “BasicTaskScheduler.cpp” should be changed from:</div>
                <div><span style="white-space:pre-wrap"> </span>fTriggersAwaitingHandling

                  = 0;</div>
                <div>to</div>
                <div><span style="white-space:pre-wrap"> </span>fTriggersAwaitingHandling

                  &=~ fLastUsedTriggerMask;</div>
                <div><br>
                </div>
                <div>I have just released a new version (2015.03.16) of
                  the code that fixes this.  You should upgrade to this
                  version.</div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div>You should also make sure that your own code
                  satisfies condition 2/.  I.e., you should make sure
                  that your code is never calling “triggerEvent()” more
                  than once with the same ‘event trigger’ value, unless
                  you’re sure that the first event (for that event
                  trigger) has already been handled.  (In particular,
                  you should never call “triggerEvent()” with the same
                  ‘event trigger’ value from more than one thread.)</div>
                <br>
                <div> <span
style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span
style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Ross
                      Finlayson<br>
                      Live Networks, Inc.<br>
                      <a moz-do-not-send="true"
                        href="http://www.live555.com/" target="_blank">http://www.live555.com/</a></span></span>
                </div>
                <div><br>
                </div>
                <br>
                <br>
                <fieldset></fieldset>
                <br>
                <pre>_______________________________________________
live-devel mailing list
<a moz-do-not-send="true" href="mailto:live-devel@lists.live555.com" target="_blank">live-devel@lists.live555.com</a>
<a moz-do-not-send="true" href="http://lists.live555.com/mailman/listinfo/live-devel" target="_blank">http://lists.live555.com/mailman/listinfo/live-devel</a>
</pre>
              </blockquote>
              <br>
            </div>
            <br>
            _______________________________________________<br>
            live-devel mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:live-devel@lists.live555.com">live-devel@lists.live555.com</a><br>
            <a moz-do-not-send="true"
              href="http://lists.live555.com/mailman/listinfo/live-devel"
              target="_blank">http://lists.live555.com/mailman/listinfo/live-devel</a><br>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
live-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:live-devel@lists.live555.com">live-devel@lists.live555.com</a>
<a class="moz-txt-link-freetext" href="http://lists.live555.com/mailman/listinfo/live-devel">http://lists.live555.com/mailman/listinfo/live-devel</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>