470,848 Members | 1,817 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

Loadlibrary(), function callbacks and multi-threading

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
2 2917
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


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.

Similar topics

2 posts views Thread by Chris Morley | last post: by
3 posts views Thread by Siegfried Heintze | last post: by
1 post views Thread by Craig Dunstan | last post: by
6 posts views Thread by Tushar | last post: by
1 post views Thread by gordon.chapman | last post: by
7 posts views Thread by ghulands | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.