<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - std::__1::binomial_distribution is not thread safe"
   href="https://bugs.llvm.org/show_bug.cgi?id=32649">32649</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::__1::binomial_distribution is not thread safe
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vincent.lebourlot@starqube.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>On mac, std::binomial_distribution calls POSIX version of lgamma which is not
thread safe (see notes on <a href="http://en.cppreference.com/w/cpp/numeric/math/lgamma">http://en.cppreference.com/w/cpp/numeric/math/lgamma</a>)
causing multiple threads to use global variables 'signgam' (libsystem_m.dylib).



==================
WARNING: ThreadSanitizer: data race (pid=64621)
  Write of size 1 at 0x7fffa6519248 by thread T89:
    #0 lgamma <null> (libclang_rt.tsan_osx_dynamic.dylib:x86_64+0x16e5b)
    #1 std::__1::binomial_distribution<unsigned
int>::param_type::param_type(unsigned int, double) <null>
(TestHisto:x86_64+0x1000418a4)
    #2 std::__1::binomial_distribution<unsigned
int>::param_type::param_type(unsigned int, double) <null>
(TestHisto:x86_64+0x100041738)
    #3 StarQube::RandomString<StarQube::String>::RandomString(bool) <null>
(TestHisto:x86_64+0x10004145d)
    #4 StarQube::Random<StarQube::String>::Random(bool) <null>
(TestHisto:x86_64+0x100040f48)
    #5 StarQube::Random<StarQube::String>::Random(bool) <null>
(TestHisto:x86_64+0x100034b1e)
    #6 StarQube::createValues(StarQube::ValueType, unsigned long,
std::__1::mersenne_twister_engine<unsigned long long, 64ul, 312ul, 156ul, 31ul,
13043109905998158313ull, 29ul, 6148914691236517205ull, 17ul,
8202884508482404352ull, 37ul, 18444473444759240704ull, 43ul,
6364136223846793005ull>&) <null> (TestHisto:x86_64+0x100009e95)
    #7 TestHisto::checkDataCross(StarQube::QuantClient const&, StarQube::String
const&, StarQube::Freq, StarQube::ValueType, StarQube::ValueType,
StarQube::ValueType, StarQube::ValueType, unsigned long, unsigned long,
unsigned long) <null> (TestHisto:x86_64+0x100008b4a)
    #8 TestHisto::testHisto(StarQube::QuantClient const&, StarQube::String
const&)::$_1::operator()() const <null> (TestHisto:x86_64+0x10005ffa3)
    #9 void
std::__1::__invoke_void_return_wrapper<void>::__call<TestHisto::testHisto(StarQube::QuantClient
const&, StarQube::String
const&)::$_1&>(TestHisto::testHisto(StarQube::QuantClient const&,
StarQube::String const&)::$_1&&&) <null> (TestHisto:x86_64+0x10005fdb0)
    #10 std::__1::__function::__func<TestHisto::testHisto(StarQube::QuantClient
const&, StarQube::String const&)::$_1,
std::__1::allocator<TestHisto::testHisto(StarQube::QuantClient const&,
StarQube::String const&)::$_1>, void ()>::operator()() <null>
(TestHisto:x86_64+0x10005f96c)
    #11 std::__1::function<void ()>::operator()() const <null>
(TestHisto:x86_64+0x1000441cc)
    #12 StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0::operator()() const <null> (TestHisto:x86_64+0x100e18280)
    #13 void*
std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct,
std::__1::default_delete<std::__1::__thread_struct> >,
StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0> >(void*) <null> (TestHisto:x86_64+0x100e19b60)

  Previous write of size 1 at 0x7fffa6519248 by thread T95:
    #0 lgamma <null> (libclang_rt.tsan_osx_dynamic.dylib:x86_64+0x16e5b)
    #1 std::__1::binomial_distribution<unsigned
int>::param_type::param_type(unsigned int, double) <null>
(TestHisto:x86_64+0x1000418a4)
    #2 std::__1::binomial_distribution<unsigned
int>::param_type::param_type(unsigned int, double) <null>
(TestHisto:x86_64+0x100041738)
    #3 StarQube::RandomString<StarQube::String>::RandomString(bool) <null>
(TestHisto:x86_64+0x10004145d)
    #4 StarQube::Random<StarQube::String>::Random(bool) <null>
(TestHisto:x86_64+0x100040f48)
    #5 StarQube::Random<StarQube::String>::Random(bool) <null>
(TestHisto:x86_64+0x100034b1e)
    #6 StarQube::createValues(StarQube::ValueType, unsigned long,
std::__1::mersenne_twister_engine<unsigned long long, 64ul, 312ul, 156ul, 31ul,
13043109905998158313ull, 29ul, 6148914691236517205ull, 17ul,
8202884508482404352ull, 37ul, 18444473444759240704ull, 43ul,
6364136223846793005ull>&) <null> (TestHisto:x86_64+0x100009e95)
    #7 TestHisto::checkDataCross(StarQube::QuantClient const&, StarQube::String
const&, StarQube::Freq, StarQube::ValueType, StarQube::ValueType,
StarQube::ValueType, StarQube::ValueType, unsigned long, unsigned long,
unsigned long) <null> (TestHisto:x86_64+0x100008b4a)
    #8 TestHisto::testHisto(StarQube::QuantClient const&, StarQube::String
const&)::$_1::operator()() const <null> (TestHisto:x86_64+0x10005ffa3)
    #9 void
std::__1::__invoke_void_return_wrapper<void>::__call<TestHisto::testHisto(StarQube::QuantClient
const&, StarQube::String
const&)::$_1&>(TestHisto::testHisto(StarQube::QuantClient const&,
StarQube::String const&)::$_1&&&) <null> (TestHisto:x86_64+0x10005fdb0)
    #10 std::__1::__function::__func<TestHisto::testHisto(StarQube::QuantClient
const&, StarQube::String const&)::$_1,
std::__1::allocator<TestHisto::testHisto(StarQube::QuantClient const&,
StarQube::String const&)::$_1>, void ()>::operator()() <null>
(TestHisto:x86_64+0x10005f96c)
    #11 std::__1::function<void ()>::operator()() const <null>
(TestHisto:x86_64+0x1000441cc)
    #12 StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0::operator()() const <null> (TestHisto:x86_64+0x100e18280)
    #13 void*
std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct,
std::__1::default_delete<std::__1::__thread_struct> >,
StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0> >(void*) <null> (TestHisto:x86_64+0x100e19b60)

  Location is global 'signgam' at 0x7fffa6519248
(libsystem_m.dylib+0x000008d0f248)

  Thread T89 (tid=15957282, running) created by main thread at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:x86_64+0x7391)
    #1
std::__1::thread::thread<StarQube::Thread::run(std::__1::vector<std::__1::function<void
()>, std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&,
void>(StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&&&) <null> (TestHisto:x86_64+0x100e19156)
    #2
std::__1::thread::thread<StarQube::Thread::run(std::__1::vector<std::__1::function<void
()>, std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&,
void>(StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&&&) <null> (TestHisto:x86_64+0x100e18848)
    #3
StarQube::Thread::Thread<StarQube::Thread::run(std::__1::vector<std::__1::function<void
()>, std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&>(StarQube::String const&,
StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&&&) <null> (TestHisto:x86_64+0x100e1845a)
    #4
StarQube::Thread::Thread<StarQube::Thread::run(std::__1::vector<std::__1::function<void
()>, std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&>(StarQube::String const&,
StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&&&) <null> (TestHisto:x86_64+0x100e17dd8)
    #5 StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned long)
<null> (TestHisto:x86_64+0x100e1779d)
    #6 TestHisto::testHisto(StarQube::QuantClient const&, StarQube::String
const&) <null> (TestHisto:x86_64+0x100017839)
    #7 TestHisto::main() <null> (TestHisto:x86_64+0x100030cb1)
    #8 StarQube::runSuite(char const*, void (*)(), bool) <null>
(TestHisto:x86_64+0x100032414)
    #9 main <null> (TestHisto:x86_64+0x10003219c)

  Thread T95 (tid=15957288, running) created by main thread at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:x86_64+0x7391)
    #1
std::__1::thread::thread<StarQube::Thread::run(std::__1::vector<std::__1::function<void
()>, std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&,
void>(StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&&&) <null> (TestHisto:x86_64+0x100e19156)
    #2
std::__1::thread::thread<StarQube::Thread::run(std::__1::vector<std::__1::function<void
()>, std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&,
void>(StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&&&) <null> (TestHisto:x86_64+0x100e18848)
    #3
StarQube::Thread::Thread<StarQube::Thread::run(std::__1::vector<std::__1::function<void
()>, std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&>(StarQube::String const&,
StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&&&) <null> (TestHisto:x86_64+0x100e1845a)
    #4
StarQube::Thread::Thread<StarQube::Thread::run(std::__1::vector<std::__1::function<void
()>, std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&>(StarQube::String const&,
StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned
long)::$_0&&&) <null> (TestHisto:x86_64+0x100e17dd8)
    #5 StarQube::Thread::run(std::__1::vector<std::__1::function<void ()>,
std::__1::allocator<std::__1::function<void ()> > > const&, unsigned long)
<null> (TestHisto:x86_64+0x100e1779d)
    #6 TestHisto::testHisto(StarQube::QuantClient const&, StarQube::String
const&) <null> (TestHisto:x86_64+0x100017839)
    #7 TestHisto::main() <null> (TestHisto:x86_64+0x100030cb1)
    #8 StarQube::runSuite(char const*, void (*)(), bool) <null>
(TestHisto:x86_64+0x100032414)
    #9 main <null> (TestHisto:x86_64+0x10003219c)

SUMMARY: ThreadSanitizer: data race
(/tmp/Compiler_2017-04-12_193601/StarQube/Config/CMake/build/TestHisto:x86_64+0x1000418a4)
in std::__1::binomial_distribution<unsigned
int>::param_type::param_type(unsigned int, double)
==================</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>