lua-users home
lua-l archive

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


Sorry, I did not recognice your first message.

Maybe you can use something like thread lokal storage.
The idea here is to use a C funktion to get a unique
id for each thread:

static int getThreadID(lua_State *L)
{
    lua_pushlightuserdata(L, L);
    return 1;
}

This id can now be used as index in a table.
The associated value would be a table for your
thread local data.

begin
    local tls = {}
    
    -- function to get thread local table
    function getTLS()
        local id = getThreadID()
        local t = tls[id]
        if not t then
            t = {}
            tls[id]=t
        end
        return t
    end

    function freeTLS()
        tls[getThreadID()] = nil
    end

end

This simple solution has one drawback: you must free 
the thread local table manualy. 

I did not test it, its yust an idea.

Maik

> -----Ursprungliche Nachricht-----
> Von: Nodir Temirhodzhaev [mailto:tnodir@land.ru]
> Gesendet: 21 April 2004 09:58
> An: lua@bazar2.conectiva.com.br
> Betreff: RE: global & unique
> 
> 
> Zimmermann, Maik wrote:
> > the problem here is that you are using the same
> > instance of pr in both coroutines. Try ...
> Yes, it works (as internal local function).
> But I want to do other thing.
> There is an external function (loaded lua-chunk), which uses 
> global variable "out" as file to output.
> And new threads call this function, but outfile is different 
> for each thread.
> How to implement such thing?
> (In 1 posting I showed how, but it's expensive.)
>