callback or threading or something else ?

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

    #1

    callback or threading or something else ?


    bool foundOrNot = 0;
    while (! foundOrNot){
    // from here do some calculations here
    ......
    ......
    // till here

    foundOrNot = doSomeWastingTi meThing(); // This function will spend
    a lot of time to get the answer of returnValue
    // do some other calculations here, for example
    ......
    ......
    ......
    // till here
    }


    Since we know that doSomewastingTi meThing( ) will spend us a lot of
    time.
    We want to do the other things till doSomeWastingTi meThing get the
    return value (foundOrNot).
    When doSomeWastingTi meThing return the answer, we begin to do something
    about the returned answer.

    Now, my question is:
    1. How can I do it in C Language? Could you show me some valid code?
    My friend told me that I may use a call back function or thread to
    achieve it. But he never did that before.
    Could someone guide me to the right direction or give me some url or
    examples?
    Thanks in advance.

    -jiing-

  • Richard Bos

    #2
    Re: callback or threading or something else ?

    "jiing" <jiing.deng@gma il.com> wrote:
    [color=blue]
    > Since we know that doSomewastingTi meThing( ) will spend us a lot of
    > time.
    > We want to do the other things till doSomeWastingTi meThing get the
    > return value (foundOrNot).
    > When doSomeWastingTi meThing return the answer, we begin to do something
    > about the returned answer.
    >
    > Now, my question is:
    > 1. How can I do it in C Language?[/color]

    You can't; not in C alone. If you are on a Unixoid, or somewhere else
    where POSIX-like threads are available, perhaps comp.unix.progr ammer can
    give you an answer; if not, your system does probably provide threading,
    but as an extension to ISO C, and you'll need to ask in a newsgroup that
    discusses programming for your compiler and/or OS.

    Richard

    Comment

    Working...