Why not provide a standard non-busy waiting method?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike3

    Why not provide a standard non-busy waiting method?

    Hi.

    Busy-waiting is a known anti-pattern that should be avoided. However,
    in C,
    there is no standard alternative, so when a wait is required and it's
    not busy,
    the program becomes 100% non-portable. So then why not include this
    type
    of non-busy wait functionality in the standard?
  • Kenneth Brody

    #2
    Re: Why not provide a standard non-busy waiting method?

    mike3 wrote:
    >
    Hi.
    >
    Busy-waiting is a known anti-pattern that should be avoided. However,
    in C, there is no standard alternative, so when a wait is required
    and it's not busy, the program becomes 100% non-portable. So then why
    not include this type of non-busy wait functionality in the standard?
    What if the underlying platform has no such support? (eg: MS-DOS.)

    Not to mention, the concept of "non-busy waiting" implies a mutli-
    tasking system.

    --
    +-------------------------+--------------------+-----------------------+
    | Kenneth J. Brody | www.hvcomputer.com | #include |
    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
    +-------------------------+--------------------+-----------------------+
    Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>

    Comment

    • Kenny McCormack

      #3
      Re: Why not provide a standard non-busy waiting method?

      In article <47BF4A4B.2DAD2 643@spamcop.net >,
      Kenneth Brody <kenbrody@spamc op.netwrote:
      >mike3 wrote:
      >>
      >Hi.
      >>
      >Busy-waiting is a known anti-pattern that should be avoided. However,
      >in C, there is no standard alternative, so when a wait is required
      >and it's not busy, the program becomes 100% non-portable. So then why
      >not include this type of non-busy wait functionality in the standard?
      >
      >What if the underlying platform has no such support? (eg: MS-DOS.)
      >
      >Not to mention, the concept of "non-busy waiting" implies a mutli-
      >tasking system.
      Anyone with couple of brain cells to rub together could see that the
      way to handle this is to allow the function to be a no-op if necessary.

      Comment

      • Keith Thompson

        #4
        Re: Why not provide a standard non-busy waiting method?

        mike3 <mike4ty4@yahoo .comwrites:
        Busy-waiting is a known anti-pattern that should be
        avoided. However, in C, there is no standard alternative, so when a
        wait is required and it's not busy, the program becomes 100%
        non-portable. So then why not include this type of non-busy wait
        functionality in the standard?
        Waiting for what?

        If the requirements for your program require it to do a non-busy wait,
        then it probably (but not certainly) needs to do some other
        system-specific stuff as well. Leaving this functionality up to the
        operating system or to a secondary standard such as POSIX isn't
        unreasonable.

        --
        Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
        Nokia
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"

        Comment

        • CBFalconer

          #5
          Re: Why not provide a standard non-busy waiting method?

          mike3 wrote:
          >
          Busy-waiting is a known anti-pattern that should be avoided.
          However, in C, there is no standard alternative, so when a wait
          is required and it's not busy, the program becomes 100%
          non-portable. So then why not include this type of non-busy wait
          functionality in the standard?
          Sure, just as soon as you describe to us a sure-fire positive
          method of so doing on all the types of systems on which C runs.
          Note the word 'all'.

          --
          [mail]: Chuck F (cbfalconer at maineline dot net)
          [page]: <http://cbfalconer.home .att.net>
          Try the download section.



          --
          Posted via a free Usenet account from http://www.teranews.com

          Comment

          • Martin

            #6
            Re: Why not provide a standard non-busy waiting method?

            On Sat, 23 Feb 2008 09:28:33 -0000, Keith Thompson <kst-u@mib.orgwrote:
            And can you describe a sure-fire positive method of determining the
            current time on all such systems? Nevertheless, the C standard
            defines the time() function (which needn't be supported on self-hosted
            implementations , and which can always return (time_t)-1 if the current
            time can't be determined).
            Indeed.

            "And furthermore, a system need only provide its 'best approximation' to
            the current time and date, or to processor time consumed, to conform to
            the C Standard. A vendor could argue that 1 January 1980 is always the
            best available approximation to any date and time. A customer can rightly
            quarrel about the low quality of such an approximation, but not whether it
            satisfies the C Standard". -- "The Standard C Library", P.J. Plauger

            It's interesting the approximation applies to the processor time consumed
            too.

            --
            Martin

            Comment

            • Kelsey Bjarnason

              #7
              Re: Why not provide a standard non-busy waiting method?

              On Fri, 22 Feb 2008 17:18:51 -0500, Kenneth Brody wrote:
              mike3 wrote:
              >>
              >Hi.
              >>
              >Busy-waiting is a known anti-pattern that should be avoided. However,
              >in C, there is no standard alternative, so when a wait is required and
              >it's not busy, the program becomes 100% non-portable. So then why not
              >include this type of non-busy wait functionality in the standard?
              >
              What if the underlying platform has no such support? (eg: MS-DOS.)
              Then it can just as readily be a busy loop. The whole point to a non-
              busy loop is to allow other processes to run; if there are no processes,
              a simple busy loop will suffice.

              Comment

              • Kelsey Bjarnason

                #8
                Re: Why not provide a standard non-busy waiting method?

                On Fri, 22 Feb 2008 20:16:58 -0500, CBFalconer wrote:
                mike3 wrote:
                >>
                >Busy-waiting is a known anti-pattern that should be avoided. However,
                >in C, there is no standard alternative, so when a wait is required and
                >it's not busy, the program becomes 100% non-portable. So then why not
                >include this type of non-busy wait functionality in the standard?
                >
                Sure, just as soon as you describe to us a sure-fire positive method of
                so doing on all the types of systems on which C runs. Note the word
                'all'.
                You have just eliminated the C standard library, at least significant
                portions of it, as your "all" requirement there can't apply to them.
                When will we be seeing the TC which eliminates all such functions from
                the language?

                Or maybe, just maybe, that "all" notion of yours is just a tired old red
                herring?

                Comment

                • Kenny McCormack

                  #9
                  Re: Why not provide a standard non-busy waiting method?

                  In article <si9b95-og.ln1@spanky.l ocalhost.net>,
                  Kelsey Bjarnason <kbjarnason@gma il.comwrote:
                  >On Fri, 22 Feb 2008 20:16:58 -0500, CBFalconer wrote:
                  >
                  >mike3 wrote:
                  >>>
                  >>Busy-waiting is a known anti-pattern that should be avoided. However,
                  >>in C, there is no standard alternative, so when a wait is required and
                  >>it's not busy, the program becomes 100% non-portable. So then why not
                  >>include this type of non-busy wait functionality in the standard?
                  >>
                  >Sure, just as soon as you describe to us a sure-fire positive method of
                  >so doing on all the types of systems on which C runs. Note the word
                  >'all'.
                  >
                  >You have just eliminated the C standard library, at least significant
                  >portions of it, as your "all" requirement there can't apply to them.
                  >When will we be seeing the TC which eliminates all such functions from
                  >the language?
                  >
                  >Or maybe, just maybe, that "all" notion of yours is just a tired old red
                  >herring?
                  >
                  CBF is just a tired old red herring.

                  Comment

                  • Kenny McCormack

                    #10
                    Re: Why not provide a standard non-busy waiting method?

                    In article <s18b95-og.ln1@spanky.l ocalhost.net>,
                    Kelsey Bjarnason <kbjarnason@gma il.comwrote:
                    >On Fri, 22 Feb 2008 17:18:51 -0500, Kenneth Brody wrote:
                    >
                    >mike3 wrote:
                    >>>
                    >>Hi.
                    >>>
                    >>Busy-waiting is a known anti-pattern that should be avoided. However,
                    >>in C, there is no standard alternative, so when a wait is required and
                    >>it's not busy, the program becomes 100% non-portable. So then why not
                    >>include this type of non-busy wait functionality in the standard?
                    >>
                    >What if the underlying platform has no such support? (eg: MS-DOS.)
                    >
                    >Then it can just as readily be a busy loop. The whole point to a non-
                    >busy loop is to allow other processes to run; if there are no processes,
                    >a simple busy loop will suffice.
                    >
                    To be thoroughly, revoltingly pedantic (i.e., the norm for the group),
                    one should point out that if I were running MSDOS on a current laptop,
                    that laptop would have facilities to shut down (or slow down) the CPU to
                    save power and reduce wear (i.e., heat buildup) on the CPU. It can't do
                    this if the program busy-loops.

                    Comment

                    • Kenneth Brody

                      #11
                      Re: Why not provide a standard non-busy waiting method?

                      Kenny McCormack wrote:
                      >
                      In article <47BF4A4B.2DAD2 643@spamcop.net >,
                      Kenneth Brody <kenbrody@spamc op.netwrote:
                      mike3 wrote:
                      >
                      Hi.
                      >
                      Busy-waiting is a known anti-pattern that should be avoided. However,
                      in C, there is no standard alternative, so when a wait is required
                      and it's not busy, the program becomes 100% non-portable. So then why
                      not include this type of non-busy wait functionality in the standard?
                      What if the underlying platform has no such support? (eg: MS-DOS.)

                      Not to mention, the concept of "non-busy waiting" implies a mutli-
                      tasking system.
                      >
                      Anyone with couple of brain cells to rub together could see that the
                      way to handle this is to allow the function to be a no-op if necessary.
                      One could say the same thing about functions to create a subdirectory,
                      open a socket, or draw a circle.

                      --
                      +-------------------------+--------------------+-----------------------+
                      | Kenneth J. Brody | www.hvcomputer.com | #include |
                      | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
                      +-------------------------+--------------------+-----------------------+
                      Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>


                      Comment

                      • Richard Heathfield

                        #12
                        Re: Why not provide a standard non-busy waiting method?

                        Keith Thompson said:

                        <snip>
                        Name one system with a hosted C implementation that doesn't have a
                        straightforward way of doing a non-busy wait.
                        MS-DOS (unless you count TSRs, which should almost certainly count as
                        cheating).

                        <snip>

                        --
                        Richard Heathfield <http://www.cpax.org.uk >
                        Email: -http://www. +rjh@
                        Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                        "Usenet is a strange place" - dmr 29 July 1999

                        Comment

                        • santosh

                          #13
                          Re: Why not provide a standard non-busy waiting method?

                          Richard Heathfield wrote:
                          Keith Thompson said:
                          >
                          <snip>
                          >
                          >Name one system with a hosted C implementation that doesn't have a
                          >straightforwar d way of doing a non-busy wait.
                          >
                          MS-DOS (unless you count TSRs, which should almost certainly count as
                          cheating).
                          <OT>

                          I think that there is nothing that potentially prevents a DOS system
                          from implementing a non-busy wait.

                          A call to sleep would invoke a system routine that would put the CPU to
                          sleep (using the HLT instruction), to be woken by the next clock
                          interrupt. The routine would of course examine the countdown timer and
                          keep calling HLT until the requested time period has elapsed.

                          </OT>

                          Comment

                          • Morris Dovey

                            #14
                            Re: Why not provide a standard non-busy waiting method?

                            Richard Heathfield wrote:
                            >
                            Keith Thompson said:
                            >
                            <snip>
                            >
                            Name one system with a hosted C implementation that doesn't have a
                            straightforward way of doing a non-busy wait.
                            >
                            MS-DOS (unless you count TSRs, which should almost certainly count as
                            cheating).
                            CP/M, as provided by Digital Research.

                            A great many CP/M users wrote their own BIOS. Mine included
                            context switching and an equivalent to sched_yield().

                            :-)

                            --
                            Morris Dovey
                            DeSoto Solar
                            DeSoto, Iowa USA

                            Comment

                            Working...