threads without threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sindica@gmail.com

    #1

    threads without threads

    Hello,

    I have a counter loop which actually executes in a different thread.
    The thread is there to check for a connection time out. However due to
    some limitations, I cannot use pthreads or any OS dependant components
    (my code should run on both windows and linux). I have to relegiously
    stick on to ANSIC standard. Does ANSI C provide any inherent function
    which could accomplish what I intend to do. Or putting it otherway,
    how can I just deviate from my direct execution path and just return
    to it after a stipulated time has elapsed.

    ~saraca
  • Joona I Palaste

    #2
    Re: threads without threads

    sindica@gmail.c om scribbled the following:[color=blue]
    > Hello,[/color]
    [color=blue]
    > I have a counter loop which actually executes in a different thread.
    > The thread is there to check for a connection time out. However due to
    > some limitations, I cannot use pthreads or any OS dependant components
    > (my code should run on both windows and linux). I have to relegiously
    > stick on to ANSIC standard. Does ANSI C provide any inherent function
    > which could accomplish what I intend to do. Or putting it otherway,
    > how can I just deviate from my direct execution path and just return
    > to it after a stipulated time has elapsed.[/color]

    ANSI C provides no thread support of any kind at all. As far as ANSI C
    is concerned, the world is a single thread.

    --
    /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/

    Comment

    • Thomas Matthews

      #3
      Re: threads without threads

      sindica@gmail.c om wrote:[color=blue]
      > Hello,
      >
      > I have a counter loop which actually executes in a different thread.
      > The thread is there to check for a connection time out. However due to
      > some limitations, I cannot use pthreads or any OS dependant components
      > (my code should run on both windows and linux). I have to relegiously
      > stick on to ANSIC standard. Does ANSI C provide any inherent function
      > which could accomplish what I intend to do. Or putting it otherway,
      > how can I just deviate from my direct execution path and just return
      > to it after a stipulated time has elapsed.
      >
      > ~saraca[/color]

      As far as sleeping goes, there is no support for task suspension
      in the ANSI C language.

      However, you _could_ write a wrapper function for your platform
      specific code. Just supply different implementations based upon
      the platform. This is what many cross platform project do.

      --
      Thomas Matthews

      C++ newsgroup welcome message:

      C++ Faq: http://www.parashift.com/c++-faq-lite
      C Faq: http://www.eskimo.com/~scs/c-faq/top.html
      alt.comp.lang.l earn.c-c++ faq:

      Other sites:
      http://www.josuttis.com -- C++ STL Library book

      Comment

      • Malcolm

        #4
        Re: threads without threads


        <sindica@gmail. com> wrote[color=blue]
        >
        > I have a counter loop which actually executes in a different thread.
        > The thread is there to check for a connection time out. However due to
        > some limitations, I cannot use pthreads or any OS dependant components
        > (my code should run on both windows and linux). I have to relegiously
        > stick on to ANSIC standard. Does ANSI C provide any inherent function
        > which could accomplish what I intend to do. Or putting it otherway,
        > how can I just deviate from my direct execution path and just return
        > to it after a stipulated time has elapsed.
        >[/color]
        You need to rewrite the code. If you are executing a long function which may
        need to abort (eg for connection time out) then pass in a callback function,
        which gets called every so often, and which returns a trigger if the
        function is to immediately abort. The callback can check the clock.


        Comment

        • William Ahern

          #5
          Re: threads without threads

          sindica@gmail.c om wrote:[color=blue]
          > Hello,[/color]
          [color=blue]
          > I have a counter loop which actually executes in a different thread.
          > The thread is there to check for a connection time out. However due to
          > some limitations, I cannot use pthreads or any OS dependant components
          > (my code should run on both windows and linux). I have to relegiously
          > stick on to ANSIC standard.[/color]

          If it's only Windows and platforms w/ POSIX threads (including Linux), then
          this might help:


          [color=blue]
          > Does ANSI C provide any inherent function which could accomplish what I
          > intend to do. Or putting it otherway, how can I just deviate from my
          > direct execution path and just return to it after a stipulated time has
          > elapsed.[/color]

          Not in ISO C, though I strongly suspect that if you're blocked on a
          "connect" that you're already using another set of interfaces. In that case
          the right answer for this particular problem couldn't be in ISO C, and
          trying to stick too closely to ISO--within the scope of this particular
          problem--will probably create more problems than benefits.

          When it comes to networking, the next level up in standards is POSIX. You
          can generally find POSIX interfaces for Windows (as in the above example).
          Ultimately you could always bundle cygwin.dll with your application:


          Comment

          Working...