Anton Korobeynikov
2009-Nov-21 18:05 UTC
[LLVMdev] Thread local data and atomic instructions
Hello> I need a shadow stack per thread and I'm not sure how to do that. Passing it > everywhere seems like a bad idea. I could put it in a global thread id -> > thread-local data mapping but that would incur lookup and locking every time > I fiddle with it (which is often!). Is it possible for me to create a global > using LLVM and mark it as thread local and use that instead?In theory - yes, but it will work only on x86/linux. No thread local stuff on darwin at all, for example. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
I'm just dabbling with threads for the first time and have hit a few problems. I need a shadow stack per thread and I'm not sure how to do that. Passing it everywhere seems like a bad idea. I could put it in a global thread id -> thread-local data mapping but that would incur lookup and locking every time I fiddle with it (which is often!). Is it possible for me to create a global using LLVM and mark it as thread local and use that instead? Less importantly, I'd like to use atomic instructions to push my state machine around (for suspending and resuming mutators) and, although I can see llvm.atomic.cmp.swap in the LLVM Language Reference, I cannot see how to emit these atomic instructions from my compiler in the APIs. How is this done? -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e
On Saturday 21 November 2009 18:05:08 Anton Korobeynikov wrote:> Hello > > > I need a shadow stack per thread and I'm not sure how to do that. Passing > > it everywhere seems like a bad idea. I could put it in a global thread id > > -> thread-local data mapping but that would incur lookup and locking > > every time I fiddle with it (which is often!). Is it possible for me to > > create a global using LLVM and mark it as thread local and use that > > instead? > > In theory - yes, but it will work only on x86/linux. No thread local > stuff on darwin at all, for example.Ugh. What if I make thread local data in the C code of my run-time (compiled with GCC) with C functions to get and set it? How does llvm-gcc handle thread local data on Darwin then? -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e