diff options
| author | Louis Dionne <ldionne@apple.com> | 2019-04-17 20:07:39 +0000 | 
|---|---|---|
| committer | Louis Dionne <ldionne@apple.com> | 2019-04-17 20:07:39 +0000 | 
| commit | 09ef420d6254f945a50da07a0a71c2c7a93b6b12 (patch) | |
| tree | 52acd8c8c01ecd59da7481a8bc00d9fd02d0bdeb | |
| parent | 25e592e52236669f72bfb54986c1197cc6b640cf (diff) | |
| download | bcm5719-llvm-09ef420d6254f945a50da07a0a71c2c7a93b6b12.tar.gz bcm5719-llvm-09ef420d6254f945a50da07a0a71c2c7a93b6b12.zip  | |
[libc++] (Take 2) Add a test that uses the debug database from multiple threads
In r358591, I added a test that uses the debug database from multiple
threads and that helped us uncover the problem that was fixed in r355367.
However, the test broke the tsan CI bots, and I think the problem is the
test allocator that was used in the test (which is not thread safe).
I'm committing again without using the test allocator, and in a separate
test file.
llvm-svn: 358610
| -rw-r--r-- | libcxx/test/libcxx/debug/containers/db_sequence_container_iterators.multithread.pass.cpp | 72 | 
1 files changed, 72 insertions, 0 deletions
diff --git a/libcxx/test/libcxx/debug/containers/db_sequence_container_iterators.multithread.pass.cpp b/libcxx/test/libcxx/debug/containers/db_sequence_container_iterators.multithread.pass.cpp new file mode 100644 index 00000000000..3cd0ce03158 --- /dev/null +++ b/libcxx/test/libcxx/debug/containers/db_sequence_container_iterators.multithread.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: windows +// UNSUPPORTED: libcpp-has-no-threads +// MODULES_DEFINES: _LIBCPP_DEBUG=1 + +// Can't test the system lib because this test enables debug mode +// UNSUPPORTED: with_system_cxx_lib + +// test multihtreaded container debugging + +#define _LIBCPP_DEBUG 1 + +#include <cassert> +#include <cstddef> +#include <deque> +#include <list> +#include <thread> +#include <vector> +#include "container_debug_tests.hpp" + + +template <typename Container> +Container makeContainer(int size) { +  Container c; +  typedef typename Container::value_type ValueType; +  for (int i = 0; i < size; ++i) +    c.insert(c.end(), ValueType(i)); +  assert(c.size() == static_cast<std::size_t>(size)); +  return c; +} + +template <typename Container> +void ThreadUseIter() { +  const size_t maxRounds = 7; +  struct TestRunner{ +    void operator()() { +      for (size_t count = 0; count < maxRounds; count++) { +        const size_t containerCount = 11; +        std::vector<Container> containers; +        std::vector<typename Container::iterator> iterators; +        for (size_t containerIndex = 0; containerIndex < containerCount; containerIndex++) { +          containers.push_back(makeContainer<Container>(3)); +          Container& c = containers.back(); +          iterators.push_back(c.begin()); +          iterators.push_back(c.end()); +        } +      } +    } +  }; + +  TestRunner r; +  const size_t threadCount = 4; +  std::vector<std::thread> threads; +  for (size_t count = 0; count < threadCount; count++) +    threads.emplace_back(r); +  r(); +  for (size_t count = 0; count < threadCount; count++) +    threads[count].join(); +} + +int main(int, char**) { +  ThreadUseIter<std::vector<int> >(); +  return 0; +}  | 

