Asynchronous functions

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

    #1

    Asynchronous functions

    Hello all,

    I've been wondering lately how would I go about writing async
    functions. What I thought of is basically using a queue and when the
    function is called, it justs enqueues the call. Then the actual
    function which does the work checks the queue every now and then and
    processes the elements. But how am I going to schedule the functions
    to check the queue? Is this going to be dependent on the underlying
    platform? I've tried to google around to find any pointers on
    strategies how to implement async functions and didn't find any. Any
    pointers are greatly appreciated.

    Regards

  • Ico

    #2
    Re: Asynchronous functions

    gamehack <gamehack@gmail .com> wrote:
    [color=blue]
    > I've been wondering lately how would I go about writing async
    > functions. What I thought of is basically using a queue and when the
    > function is called, it justs enqueues the call. Then the actual
    > function which does the work checks the queue every now and then and
    > processes the elements. But how am I going to schedule the functions
    > to check the queue? Is this going to be dependent on the underlying
    > platform? I've tried to google around to find any pointers on
    > strategies how to implement async functions and didn't find any. Any
    > pointers are greatly appreciated.[/color]

    If you want to stick to standard C, I'm afraid you will have to poll the
    queue every now and then.

    If your platform supports threads and basic synchronisation mechanisms,
    using a separate thread for handling the queue would be the way to go.
    Using platform-specific interfaces makes this subject off-topic in this
    newsgroup, unfortunately.

    --
    :wq
    ^X^Cy^K^X^C^C^C ^C

    Comment

    • gamehack

      #3
      Re: Asynchronous functions

      As I want to stick to standard C, is there a way to "you will have to
      poll the queue every now and then." ?

      Thanks


      Ico wrote:[color=blue]
      > gamehack <gamehack@gmail .com> wrote:
      >[color=green]
      > > I've been wondering lately how would I go about writing async
      > > functions. What I thought of is basically using a queue and when the
      > > function is called, it justs enqueues the call. Then the actual
      > > function which does the work checks the queue every now and then and
      > > processes the elements. But how am I going to schedule the functions
      > > to check the queue? Is this going to be dependent on the underlying
      > > platform? I've tried to google around to find any pointers on
      > > strategies how to implement async functions and didn't find any. Any
      > > pointers are greatly appreciated.[/color]
      >
      > If you want to stick to standard C, I'm afraid you will have to poll the
      > queue every now and then.
      >
      > If your platform supports threads and basic synchronisation mechanisms,
      > using a separate thread for handling the queue would be the way to go.
      > Using platform-specific interfaces makes this subject off-topic in this
      > newsgroup, unfortunately.
      >
      > --
      > :wq
      > ^X^Cy^K^X^C^C^C ^C[/color]

      Comment

      • Ico

        #4
        Re: Asynchronous functions

        gamehack <gamehack@gmail .com> wrote:
        [color=blue]
        > Ico wrote:[color=green]
        >> gamehack <gamehack@gmail .com> wrote:
        >>[color=darkred]
        >> > I've been wondering lately how would I go about writing async
        >> > functions. What I thought of is basically using a queue and when the
        >> > function is called, it justs enqueues the call. Then the actual
        >> > function which does the work checks the queue every now and then and
        >> > processes the elements. But how am I going to schedule the functions
        >> > to check the queue? Is this going to be dependent on the underlying
        >> > platform? I've tried to google around to find any pointers on
        >> > strategies how to implement async functions and didn't find any. Any
        >> > pointers are greatly appreciated.[/color]
        >>
        >> If you want to stick to standard C, I'm afraid you will have to poll the
        >> queue every now and then.
        >>
        >> If your platform supports threads and basic synchronisation mechanisms,
        >> using a separate thread for handling the queue would be the way to go.
        >> Using platform-specific interfaces makes this subject off-topic in this
        >> newsgroup, unfortunately.
        >>[/color]
        > As I want to stick to standard C, is there a way to "you will have to
        > poll the queue every now and then." ?[/color]

        Supposing you have a function that checks if there are requests waiting
        in the the queue and calls one or more of the functions, you will just
        have to call this function at regular intervals. If your program has
        some kind of main event loop, somewhere withing this loop would be a
        good place. The best choice depends on your program flow, and is
        something only you can decide.



        --
        :wq
        ^X^Cy^K^X^C^C^C ^C

        Comment

        • Nils O. Selåsdal

          #5
          Re: Asynchronous functions

          gamehack wrote:[color=blue]
          > As I want to stick to standard C, is there a way to "you will have to
          > poll the queue every now and then." ?[/color]
          You have to insert calls such as
          run_my_queue();
          At different points in your code, where run_my_queue()
          goes through the queue, executes the operations, and returns
          when all is done..

          Comment

          Working...