[trans-mem] Do not instrument thread locals

Patrick Marlier patrick.marlier@gmail.com
Wed Jan 25 02:30:00 GMT 2012


On 01/24/2012 08:32 PM, Andi Kleen wrote:
>> Hi,
>> >
>> >  I found that all thread local variables are instrumented with
>> >  _ITM_W/R* calls whereas they should not be shared with other
>> >  threads. This patch takes care of thread locals into requires_barrier
>> >  and also adds the local save/restore for them. This patch also
>> >  includes a testcase.
> What happens when the address of the thread local escapes?
> It could well be written by another thread then.
>
> I guess you have to check for escapes here.

Thanks to raise the question and I hope I understand your point.

Did you mean something like this?

__thread int myvalue;
void bar()
{
   foo(&myvalue);
   __transaction_atomic {
     myvalue++;
   }
}

where foo shares the pointer to other threads?

 From my point of view, no. When it is a thread local, it should not be 
shared to someone else. If the thread dies, what happens to the thread 
local variable? Should it be discarded completely and this piece of 
memory never reallocated? Even if the programmer take care of this 
situation, does it make sense to share a thread local to other threads?

Anyway, you are probably right but I would prefer let the knowledgeable 
people answer instead of me, the little jedi...
--
Patrick.




More information about the Gcc-patches mailing list