c++ event sink

E

Eric Kaplan

I have a function that will download XML from internet and load XML
data into database.

The function will take 5 - 20 minutes to finish.

I heard I should use event sink (event listener) when function is
finished the task, then it will notify the caller.

So I am planning to create a seperate thread to do the long XML
loading function by using - _beginthreadex()

But how to create a notification / event sink / event listener in C++?

any library can easily just a library function call?

or any sample source code on the internet?

Thanks
 
E

Eric Kaplan

that's a very good point, how to start a seperate process from the
code?

and how can I notify the caller when the process is finished?
 
S

sk_usenet

Eric Kaplan said:
I have a function that will download XML from internet and load XML
data into database.

The function will take 5 - 20 minutes to finish.

I heard I should use event sink (event listener) when function is
finished the task, then it will notify the caller.

So I am planning to create a seperate thread to do the long XML
loading function by using - _beginthreadex()

There is no concept of thread or process as far as the C++ language is
concerned. People would scream your question as OT here :). You should try
your platform specific newsgroup.
But how to create a notification / event sink / event listener in C++?

any library can easily just a library function call?

or any sample source code on the internet?

Search engines are your friend.
 
S

Stefan Ram

sk_usenet said:
There is no concept of thread or process as far as the C++
language is concerned.

»When an exception is thrown, control is transferred to
the nearest handler with a matching type (15.3); "nearest"
means the handler for which the compound-statement,
ctor-initializer, or function-body following the try
keyword was most recently entered by the thread of control
and not yet exited.« ¯¯¯¯¯¯

ISO/IEC 14882:2003(E), 15.1p2

»If a function is registered with atexit (see <cstdlib>,
18.3) then following the call to exit, any objects with
static storage duration initialized prior to the
registration of that function shall not be destroyed until
the registered function is called from the termination
process and has completed.«
¯¯¯¯¯¯¯
ISO/IEC 14882:2003(E), 3.6.3p3
 
S

sk_usenet

Stefan Ram said:
»When an exception is thrown, control is transferred to
the nearest handler with a matching type (15.3); "nearest"
means the handler for which the compound-statement,
ctor-initializer, or function-body following the try
keyword was most recently entered by the thread of control
and not yet exited.« ¯¯¯¯¯¯

ISO/IEC 14882:2003(E), 15.1p2

»If a function is registered with atexit (see <cstdlib>,
18.3) then following the call to exit, any objects with
static storage duration initialized prior to the
registration of that function shall not be destroyed until
the registered function is called from the termination
process and has completed.«
¯¯¯¯¯¯¯
ISO/IEC 14882:2003(E), 3.6.3p3

Ok, pedantically speaking Standard does recognize something of a thread, and
something of a process. But the bottom line is that OP's question was
off-topic.
 
E

Eric Kaplan

Thanks your hint!

but i think it may not be a good idea to use such big library for a
small task.

Does using call back function a good idea in here? (loading XML to
DB, after finish, notify the main / primary thread)
 
D

Davis King

Thanks your hint!

but i think it may not be a good idea to use such big library for a
small task.

Does using call back function a good idea in here? (loading XML to
DB, after finish, notify the main / primary thread)

I believe you can also use the boost::bind library (http://
www.boost.org/doc/libs/1_35_0/libs/bind/bind.html) to create the sort
of callbacks you would be interested in.

You might also want to take a look at the
dlib::member_function_pointer object which is similar but may be
easier to use depending on what you are trying to accomplish. See,
http://dclib.sourceforge.net/other.html#member_function_pointer and
http://dclib.sourceforge.net/member_function_pointer_ex.cpp.html

-Davis
 

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
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top