Page 1 of 1

NTL 9.8.0: thread safety for the masses

PostPosted: Tue Apr 26, 2016 1:45 pm
by victorshoup
So I finally figured out a way to get NTL to work in thread-safe mode
on a much broader range of platforms, including Mac OSX (10.10 and above)
and Linux with somewhat older gcc's (gcc version 4.8 and above).

This new version of NTL still requires many C++11 features in
thread-safe mode, but it does not require "thread_local" storage.
Rather, by default, it only uses gcc's older and simpler "__thread"
storage, along with some direct calls to pthread library functions.
One can override this default behavior by configuring with
NTL_DISABLE_TLS_HACK=on. With this hack disabled,
NTL still makes use of "__thread" storage wherever possible,
and only uses "thread_local" storage for certain variables
at block scope (and none at namespace scope). This generally
leads to more efficient access to TLS variables and reduces the
requirements on the compiler and run-time: many implementations
of thread_local, especially at namespace scope, tend to be
buggy and inefficient.

To get thread safety, one still needs to configure with NTL_THREADS=on,

I have no idea if any of this works on Windows. It would be interesting to
test some of this in Cygwin. I just learned that Cygwin can give you
an LP64 data model, which is very nice. I don't have access to a Windows
machine, so I can't test any of this myself.