threads without threads

Discussion in 'C Programming' started by sindica@gmail.com, Aug 27, 2004.

  1. Guest

    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
     
    , Aug 27, 2004
    #1
    1. Advertising

  2. scribbled the following:
    > 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.


    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 () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
     
    Joona I Palaste, Aug 27, 2004
    #2
    1. Advertising

  3. wrote:
    > 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


    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:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.comeaucomputing.com/learn/faq/
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
     
    Thomas Matthews, Aug 27, 2004
    #3
  4. Malcolm Guest

    <> wrote
    >
    > 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.
    >

    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.
     
    Malcolm, Aug 27, 2004
    #4
  5. wrote:
    > 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.


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

    http://sources.redhat.com/pthreads-win32/

    > 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.


    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:

    http://www.cygwin.com/
     
    William Ahern, Aug 27, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cppaddict
    Replies:
    20
    Views:
    843
    Chris Uppal
    Aug 11, 2004
  2. Twisted
    Replies:
    1
    Views:
    1,109
    Twisted
    Feb 24, 2006
  3. yoda
    Replies:
    2
    Views:
    472
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,508
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    177
    Une bévue
    Jun 14, 2006
Loading...

Share This Page