On Tue, Aug 16, 2011 at 7:51 PM, Paolo Bonzini <pbonz...@redhat.com> wrote: > Win32 emulated TLS is slow and is not available on all versions of GCC. > Actually, Win32 does have support for decent TLS, only GCC does not map > __thread to it. The good news is, it's perfectly possible to declare > TLS variables with simple C code! > > This patch adds wrappers to qemu-thread that will use __thread on POSIX > systems, and the .tls segment on Windows. > > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > --- > It does kinda uglify the declarations, but not too much IMO. > Do we want to go this way? It will certainly limit the number > of bug reports we get. > > coroutine-win32.c | 7 +++++-- > qemu-thread-posix.h | 4 ++++ > qemu-thread-win32.c | 17 +++++++++++++++++ > qemu-thread-win32.h | 40 +++++++++++++++++++++++++++++++++++++++- > qemu-thread.h | 2 ++ > 5 files changed, 67 insertions(+), 3 deletions(-)
Hmm...this is pretty ugly low-level stuff. glib provides portable TLS although I have found __thread significantly faster on Linux. I think our options are: 1. Use __thread and require recent gcc versions on Windows. Not as fast as native Windows TLS. 2. Implement our own TLS abstraction to use native TLS on each platform. 3. Use glib TLS (GStaticPrivate). It's slower than __thread on Linux but seems portable. Options 1 and 3 seem better because they do not involve us reimplementing yet more platform abstractions. Option 1 would be nicest. Do you know which Windows gcc versions support __thread and if it would be reasonable to require those versions? Stefan