[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: my module crashes when used with lanes
- From: Benoit Germain <bgermain@...>
- Date: Fri, 11 Dec 2009 14:16:21 +0100
> M$ doc says that CoInitializeEx and CoUninitialize must be called in pairs from each thread using COM.
> However, I get an error using the following script :
> require "lanes"
> require "xbdm" -- causes xbdm init -> CoInitialize in main thread
> local function laneFunc()
> require "xbdm" -- causes xbdm init -> CoInitialize in lane thread
> --local manager = xbdm.getManager()
> local lanegen = lanes.gen( "package", laneFunc)
> local mylane = lanegen() -- lane thread starts -> xbdm required -> CoInitialize called in lane thread
> mylane:join() -- lane thread terminates -> xbdm collected -> CoUnititialize not in the lane thread but in main thread!!!
> If it was called in the main thread, then the check in your __gc method
> should have catched that. Did it?
> --> if( GetCurrentThreadId() != ud->threadId)
> Could you print the thread ids (in your main and in your __gc) and post
> the results?
the result of the execution with printf() added in luaopen_xbdm and luaxbdm_gc:
luaopen_xbdm: threadId = 4596
luaopen_xbdm: threadId = 1836
luaxbdm_gc: userdata threadId = 1836, current thread id = 4596
luaxbdm_gc: userdata threadId = 4596, current thread id = 4596
the string issued by luaL_error doesn't reach the lane's join() return values.
> Also, maybe not directly related, but bear in mind that if your threads
> join an apartment (an STA in your case) then your thread must pump messages.
> You might want to try to join the MTA (COINIT_MULTITHREADED)
The fact is, I am using IUP, and it initializes itself with APARTMENTTHREADED. I wouldn't want to get a different initialisation model depending on the order the modules are required. And maybe IUP already takes care of all the necessary pumping :-)