Skip to main content
GameDev.net gamedev.net
🔒 Locked

asynchronous function

Started by Eric_B Jan 23, 2003 at 4:31 PM 7 replies 250+ views
Original Post
Eric_B
Eric_B
how do I create asynchronous function? thanks in advance
Eric_B
Eric_B
anyone
kieren_j
kieren_j
CreateThread()
DerekSaw
DerekSaw
... or _beginthreadex()
"after many years of singularity, i'm still searching n the event horizon" o
Neophyte
Neophyte
Or, if you''re running a *nix OS, pthread_create()

-Neophyte
Eric_B
Eric_B
I don't want to create a new thread, I just want a function that returns right after passing the parameters to another fuction like postmessage function for windows.

I'm using a timer control for this, but I want to make my own function that has the same effect.

I could make a thread and use postthreadmessage function but is there any other less complex way?

Any ideas ?

[edited by - Eric_B on January 24, 2003 5:28:41 AM]
niyaw
niyaw
i/o completion ports
asynchronous procedure calls (APC)
thread pools

you understand that one thread cannot execute two pieces of code simultaneously, right? APCs, see for instance QueueUserAPC, will only be executed when your thread is in alertable wait state, and thus is not executing any code. APCs are closest to PostMessage/GetMessage combo that you''re describing. thread pools (see, for instance, QueueUserWorkItem) are also similar in that you use them in much the same way, but the actual procedure is run on another thread and thus can run at the same time as the thread that called QueueUserWorkItem.

i/o completion ports can be used for non-i/o purposes, but you need to manage the threads yourself. iocp requires alertable waiting.

there are really two ways to get things done asynchronously:
- start a new thread for background processing - CreateThread, thread pooling, and iocp fall here
- execute the code on the same thread that called it, but delay execution until the thread is waiting - APCs and windows messages fall here.
Eric_B
Eric_B
niyaw, thanks for the reply.

I have an outprocess com dll and implemented an event, but the main problem is the client waits for the funtion (in my out-of-process com dll) to finish. The function in com dll takes a lot of time and I don't want my client to wait for the return. I've tried function pointers and everything I could think, but the client still waits for the return.

what are asynchronous procedure calls (APC), how do you make these calls?

thanks

[edited by - Eric_B on January 24, 2003 7:24:09 AM]
niyaw
niyaw
quote:
Original post by Eric_B
I have an outprocess com dll and implemented an event, but the main problem is the client waits for the funtion (in my out-of-process com dll) to finish. The function in com dll takes a lot of time and I don''t want my client to wait for the return. I''ve tried function pointers and everything I could think, but the client still waits for the return.


have you considered asynchronous RPC (remote procedure call)? it may not be as easy to use as com objects (and i''ve never heard of our-of-process com *dll*s), but they have pretty cool async call support.
quote:

what are asynchronous procedure calls (APC), how do you make these calls?


use QueueUserAPC function. APC is a piece of code that''s executing while a thread is performing an alertable wait on something, be that a kernel object, a windows message, or an i/o completion event.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.