Asynchronous functions

G

gamehack

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
 
I

Ico

gamehack said:
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.

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

gamehack

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
 
I

Ico

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

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

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

gamehack said:
As I want to stick to standard C, is there a way to "you will have to
poll the queue every now and then." ?
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..
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top