File: std_thread.cpp

package info (click to toggle)
valgrind 1%3A3.12.0~svn20160714-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 120,428 kB
  • ctags: 70,855
  • sloc: ansic: 674,645; exp: 26,134; xml: 21,574; asm: 7,570; cpp: 7,567; makefile: 7,380; sh: 6,188; perl: 5,855; haskell: 195
file content (69 lines) | stat: -rw-r--r-- 1,782 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Test whether no race conditions are reported on std::thread. Note: since
// the implementation of std::thread uses the shared pointer implementation,
// that implementation has to be annotated in order to avoid false positives.
// See also http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html for more
// information.

#include "../../drd/drd.h"
#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(addr) \
  ANNOTATE_HAPPENS_BEFORE(addr)
#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(addr) \
  ANNOTATE_HAPPENS_AFTER(addr)

#include <iostream>
#include <thread>

int main(int argc, char** argv)
{
  std::thread t( []() { } );
  t.join();
  std::cerr << "Done.\n";
  return 0;
}

#if defined(__GNUC__) && __GNUC__ -0 < 6
//
// From libstdc++-v3/src/c++11/thread.cc
//

extern "C" void* _v_execute_native_thread_routine(void* __p)
{
  std::thread::_Impl_base* __t = static_cast<std::thread::_Impl_base*>(__p);
  std::thread::__shared_base_type __local;
  __local.swap(__t->_M_this_ptr);

  __try {
    __t->_M_run();
  } __catch(const __cxxabiv1::__forced_unwind&) {
    __throw_exception_again;
  } __catch(...) {
    std::terminate();
  }

  return 0;
}

#include <system_error>

namespace std
{
  void thread::_M_start_thread(__shared_base_type __b)
  {
    if (!__gthread_active_p())
#if __EXCEPTIONS
      throw system_error(make_error_code(errc::operation_not_permitted),
                         "Enable multithreading to use std::thread");
#else
      __throw_system_error(int(errc::operation_not_permitted));
#endif

    __b->_M_this_ptr = __b;
    int __e = __gthread_create(&_M_id._M_thread, _v_execute_native_thread_routine,
                               __b.get());
    if (__e) {
      __b->_M_this_ptr.reset();
      __throw_system_error(__e);
    }
  }
}
#endif