--- In [email protected], "swzoh" <sean...@...> wrote: > > --- In [email protected], "entropyreduction" > <alancampbelllists+yahoo@> wrote: > > > > Sorry, it's been a long time since I wrote that code, so I forget > > rationale. I think I tried it without thread and powerpro locked up. > > So I went and looked at example COM code lying about, found a lot of work > > was getting done on extra threads, tried that, worked.
> Ah, I vaguely recalled that you once said that. > Anyway, using new thread (at each object creation, right?) sounds scary to > me. No, a single thread. Calls CoInitialize() as it starts, then after a bit of housekeeping waits on single object for an event. The code for each possible dll service gets a pointer to an object corresponding to that service, assigns it to a pointer to a member of type CComActionAbstract (of type that's a superclass of all classes corresponding to action types), called. Then it raises event that unblocks the service thread, and waits on another event that will be signalled when that thread is done it's work. When thread wakes up, it calls m_pCComActionAbstract->doIt(), polymorphic. Then resets its own event, signals the event that unblocks service call code, and waits. > How do you manage to clean-up those threads at unload time? How you call the > created objects, which reside in the different thread(s) from the calling > thread, i.e. PP's main thread? Thread switch or marshaling or etc? > I can imagine one scenario which crashes PP at com.unload(). In which thread > do you call CoUninitialize()? It should be the new-thread, but if mistakenly > call it in the main-thread, it could crash PP. CoUninitialize call is definitely the problem: in debugger when I step through the one thread's code, it calls CoUninitialize in the special case where m_pCComActionAbstract->doIt() returns false, only done by the polymorphic version of CComActionRealeaseAll::doIt() (called when you invoke release_all or when you unload. Might be a thread priority problem. Investigations continue. Wanna see the thread code?
