Re: Synchronization problems
On Sat, 5 Jan 2008 01:46:48 +0200, "Kurz" <Kurz@goren.org.ir> wrote:
I have a main MFC executable which loads and run few Dll's. In the main
program I have a thread that uses a try/catch block. When the thread fails
it jumps to an exception in the catch block, then the thread terminates. I
want it to hold its termination inside the exception block, until certain
conditions occur in the dll's. Specifically, I want it to wait until any of
2 routines in some dll (which run periodically) are not in the middle of
I have few questions regarding that-
Is it legal to call dll exported functions from an exception block?
Yes. Note that to catch C++ exceptions across module (EXE/DLL) boundaries,
all the modules should link to the same CRT DLL.
Can I use system events for that? If so, how would the event state in the
dll, be known by the main program?
You would have to devise a way for the modules to use the same event
objects; for example, the main program could create them all and pass their
handles to the DLL via some exported initialization function. As for
checking state, you would use WaitForSingleObject,
Can I use simple flags for that?
You could, but there's no way to wait on them efficiently. You'd have to
poll them in a loop, and since multiple threads will be using these
objects, you'd have to deal with synchronization. Using events circumvents
Visual C++ MVP