lua-users home
lua-l archive

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


Benoit Germain wrote:
Hello,

...

int luaxbdm_gc( lua_State * L)
{
        XbdmUD * const ud = static_cast<XbdmUD *>( lua_touserdata( L, 1));
        if( GetCurrentThreadId() != ud->threadId)
        {
                return luaL_error( L, "__gc called from wrong thread!");
        }
        if( ud->hr == S_OK || ud->hr == S_FALSE)

Or more easily: if(SUCCEEDED(hr))




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?

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.

http://www.codeguru.com/cpp/com-tech/activex/apts/article.php/c5533.

You might want to try to join the MTA (COINIT_MULTITHREADED)


Regards,
Ignacio