lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> 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()
> end
> 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:

>lua LanesBug.wlua
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 :-)