lightning
[Top][All Lists]
Advanced

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

Re: [Lightning] Thread-local data?


From: Paolo Bonzini
Subject: Re: [Lightning] Thread-local data?
Date: Fri, 23 Sep 2016 17:56:30 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0


On 23/09/2016 17:10, Basile Starynkevitch wrote:
>> > How can a dynamically compiled program via GNU lightning, access
>> > thread-local variables that are annotated with  _Thread_local? If I
>> > understand correctly, thread-local storage is accessed via a
>> > privileged register, so does lightning identify this register in some
>> > way?
> GNU lightning is known (and so is TinyCC) to emit slow machine code,
> but is able to emit that code very quickly.
> 
> So I would simply hand-code in C the few functions retrieving and
> updating these thread local data and call these functions as you would
> call any (external) function in GNU lightning.

One possibility is to make a struct with the addresses of the
thread-local variables you need (the struct can itself be in
thread-local storage) and pass the address of the struct to the
function.  That is:

    _Thread_local int a, b;

    typedef struct {
        int *a, *b;
    } LightningTLSData;

    _Thread_local LightningTLSData lightning_tls;

Then when running the lightning code use a wrapper:

    int (*lightning_fibonacci)(LightningTLSData *tls, int x);

    int fibonacci(int x)
    {
        if (!lightning_tls.a) {
            lightning_tls.a = &a;
            lightning_tls.b = &b;
        }
        return lightning_fibonacci(&lightning_tls, x);
    }

Depending on how you create threads, there might be a natural place to
initialize the struct.

Thanks,

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]