By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,364 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,364 IT Pros & Developers. It's quick & easy.

Loadlibrary(), function callbacks and multi-threading

P: n/a
I am writing an application that requires me to load a (Win32 C) libray
and then register several call back functions.

I am loading the libary in a worker thread and then registering
functions in the worker thread in the loaded library.

Two questions

1). Does loadlibrary(0 run the executable in the same thread as the
calee (probably not)
2). Is it safe to register/call callback funcs accross threads (assuming
functions are written so as note to alter state of calee)

Apr 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Bit byte wrote:
I am writing an application that requires me to load a (Win32 C)
libray and then register several call back functions.

I am loading the libary in a worker thread and then registering
functions in the worker thread in the loaded library.

Two questions

1). Does loadlibrary(0 run the executable in the same thread as the
calee (probably not)
LoadLibrary doesn't "run the executable" when loading a DLL, except for the
DllMain function. That IS run in the context of the thread that called
LoadLibrary. Subsequent calls to fuinctions in the DLL will occur in
whatever thread(s) make the call(s) - there's no hidden thread switch back
to the thread that loaded the DLL or anything like that (in contrast with,
for example, calling into a STA-threaded COM object, where such a thread
switch does indeed occur).
2). Is it safe to register/call callback funcs accross threads
(assuming functions are written so as note to alter state of calee)


As long as the callback registration mechanism is thread safe, then yes.

-cd
Apr 3 '06 #2

P: n/a


Carl Daniel [VC++ MVP] wrote:
Bit byte wrote:
I am writing an application that requires me to load a (Win32 C)
libray and then register several call back functions.

I am loading the libary in a worker thread and then registering
functions in the worker thread in the loaded library.

Two questions

1). Does loadlibrary(0 run the executable in the same thread as the
calee (probably not)

LoadLibrary doesn't "run the executable" when loading a DLL, except for the
DllMain function. That IS run in the context of the thread that called
LoadLibrary. Subsequent calls to fuinctions in the DLL will occur in
whatever thread(s) make the call(s) - there's no hidden thread switch back
to the thread that loaded the DLL or anything like that (in contrast with,
for example, calling into a STA-threaded COM object, where such a thread
switch does indeed occur).

2). Is it safe to register/call callback funcs accross threads
(assuming functions are written so as note to alter state of calee)

As long as the callback registration mechanism is thread safe, then yes.

-cd

Thanks for the clarification

Apr 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.