thread: New.

2008-09-12  Chris Fairles <chris.fairles@gmail.com>
	    Benjamin Kosnik  <bkoz@redhat.com>

	* include/std/thread: New.
	* include/Makefile.am: Update.
	* include/Makefile.in: Regenerate.
	* src/thread.cc: New.
	* src/Makefile.am: Update.
	* src/Makefile.in: Regenerate.
	* acinclude.m4: Add check for nanosleep.
	* configure.ac: Call it.
	* configure: Regenerate.
	* config.h.in: Likewise.
	* config/abi/pre/gnu.ver: Add exports.
	* doc/doxygen/user.cfg.in: Add thread header.
	* testsuite/lib/libstdc++.exp (check_v3_target_nanosleep): Add.
	* testsuite/lib/dg-options.exp (dg-require-nanosleep): Add.
	* testsuite/30_threads/thread/cons/1.cc: New.
	* testsuite/30_threads/thread/cons/2.cc: Likewise.
	* testsuite/30_threads/thread/cons/3.cc: Likewise.
	* testsuite/30_threads/thread/cons/4.cc: Likewise.
	* testsuite/30_threads/thread/algorithm/1.cc: Likewise.
	* testsuite/30_threads/thread/algorithm/2.cc: Likewise.
	* testsuite/30_threads/thread/member/1.cc: Likewise.
	* testsuite/30_threads/thread/member/2.cc: Likewise.
	* testsuite/30_threads/thread/member/3.cc: Likewise.
	* testsuite/30_threads/thread/this_thread/1.cc: Likewise.
	* testsuite/30_threads/thread/this_thread/2.cc: Likewise.
	* testsuite/30_threads/thread/this_thread/3.cc: Likewise.
	* testsuite/30_threads/thread/this_thread/4.cc: Likewise.
	* testsuite/30_threads/headers/thread/types_std_c++0x.cc: Likewise.
	* testsuite/30_threads/headers/thread/std_c++0x_neg.cc: Likewise.
	* testsuite/17_intro/headers/c++200x/all.cc: Add thread.
	* testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: 
	Add thread, condition_variable and mutex.

Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com>

From-SVN: r140332
This commit is contained in:
Chris Fairles 2008-09-13 00:32:37 +00:00 committed by Paolo Carlini
parent 8270e80020
commit 46e113bf2b
31 changed files with 1854 additions and 4 deletions

View File

@ -1,3 +1,39 @@
2008-09-12 Chris Fairles <chris.fairles@gmail.com>
Benjamin Kosnik <bkoz@redhat.com>
* include/std/thread: New.
* include/Makefile.am: Update.
* include/Makefile.in: Regenerate.
* src/thread.cc: New.
* src/Makefile.am: Update.
* src/Makefile.in: Regenerate.
* acinclude.m4: Add check for nanosleep.
* configure.ac: Call it.
* configure: Regenerate.
* config.h.in: Likewise.
* config/abi/pre/gnu.ver: Add exports.
* doc/doxygen/user.cfg.in: Add thread header.
* testsuite/lib/libstdc++.exp (check_v3_target_nanosleep): Add.
* testsuite/lib/dg-options.exp (dg-require-nanosleep): Add.
* testsuite/30_threads/thread/cons/1.cc: New.
* testsuite/30_threads/thread/cons/2.cc: Likewise.
* testsuite/30_threads/thread/cons/3.cc: Likewise.
* testsuite/30_threads/thread/cons/4.cc: Likewise.
* testsuite/30_threads/thread/algorithm/1.cc: Likewise.
* testsuite/30_threads/thread/algorithm/2.cc: Likewise.
* testsuite/30_threads/thread/member/1.cc: Likewise.
* testsuite/30_threads/thread/member/2.cc: Likewise.
* testsuite/30_threads/thread/member/3.cc: Likewise.
* testsuite/30_threads/thread/this_thread/1.cc: Likewise.
* testsuite/30_threads/thread/this_thread/2.cc: Likewise.
* testsuite/30_threads/thread/this_thread/3.cc: Likewise.
* testsuite/30_threads/thread/this_thread/4.cc: Likewise.
* testsuite/30_threads/headers/thread/types_std_c++0x.cc: Likewise.
* testsuite/30_threads/headers/thread/std_c++0x_neg.cc: Likewise.
* testsuite/17_intro/headers/c++200x/all.cc: Add thread.
* testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc:
Add thread, condition_variable and mutex.
2008-09-10 Paolo Carlini <paolo.carlini@oracle.com>
* src/ctype.cc (use_facet<ctype<char> >, use_facet<ctype<wchar_t>):

View File

@ -1200,6 +1200,39 @@ AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
AC_LANG_RESTORE
])
dnl
dnl Check for nanosleep, used in the implementation of 30.2.2
dnl [thread.thread.this] in the current C++0x working draft.
dnl
AC_DEFUN([GLIBCXX_CHECK_NANOSLEEP], [
AC_MSG_CHECKING([for nanosleep])
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fno-exceptions"
ac_has_nanosleep=no;
AC_CHECK_HEADERS(time.h, ac_has_time_h=yes, ac_has_time_h=no)
if test x"$ac_has_time_h" = x"yes"; then
AC_MSG_CHECKING([for nanosleep])
AC_TRY_COMPILE([#include <time.h>],
[timespec ts; nanosleep(&ts, 0);],
[ac_has_nanosleep=yes], [ac_has_nanosleep=no])
AC_MSG_RESULT($ac_has_nanosleep)
fi
if test x"$ac_has_nanosleep" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1,
[ Defined if nanosleep is available. ])
fi
CXXFLAGS="$ac_save_CXXFLAGS"
AC_LANG_RESTORE
])
dnl
dnl Check for ISO/IEC 9899:1999 "C99" support to ISO/IEC DTR 19768 "TR1"
dnl facilities in Chapter 8, "C compatibility".

View File

@ -412,6 +412,9 @@
/* Define to 1 if you have the <tgmath.h> header file. */
#undef HAVE_TGMATH_H
/* Define to 1 if you have the <time.h> header file. */
#undef HAVE_TIME_H
/* Define to 1 if the target supports thread-local storage. */
#undef HAVE_TLS
@ -791,6 +794,9 @@
/* Define if code specialized for long long should be used. */
#undef _GLIBCXX_USE_LONG_LONG
/* Defined if nanosleep is available. */
#undef _GLIBCXX_USE_NANOSLEEP
/* Define if NLS translations are to be used. */
#undef _GLIBCXX_USE_NLS

View File

@ -128,7 +128,11 @@ GLIBCXX_3.4 {
std::strstream*;
std::strstreambuf*;
# std::t[a-q]*;
std::t[a-n]*;
std::t[a-g]*;
std::th[a-h]*;
std::th[j-q]*;
std::th[s-z]*;
std::t[i-n]*;
std::tr1::h[^a]*;
std::t[s-z]*;
# std::[A-Zu-z]*;
@ -900,6 +904,23 @@ GLIBCXX_3.4.11 {
_ZNSt22condition_variable_anyD1Ev;
_ZNSt22condition_variable_anyD2Ev;
# thread
_ZNKSt6thread6get_idEv;
_ZNKSt6thread8joinableEv;
_ZNSt10shared_ptrISt18__thread_data_baseED1Ev;
_ZNSt11this_thread5yieldEv;
_ZNSt11this_thread6get_idEv;
_ZNSt12bad_weak_ptrD0Ev;
_ZNSt12bad_weak_ptrD1Ev;
_ZNSt6thread14__start_threadEv;
_ZNSt6thread4joinEv;
_ZNSt6thread4swapEOS_;
_ZNSt6thread6detachEv;
_ZNSt6threadC1Ev;
_ZNSt6threadC2Ev;
_ZNSt6threadD1Ev;
_ZNSt6threadD2Ev;
# system_error
_ZSt18get_posix_categoryv;
_ZSt19get_system_categoryv;

240
libstdc++-v3/configure vendored
View File

@ -21736,6 +21736,246 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
# For nanosleep support
echo "$as_me:$LINENO: checking for nanosleep" >&5
echo $ECHO_N "checking for nanosleep... $ECHO_C" >&6
ac_ext=cc
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fno-exceptions"
ac_has_nanosleep=no;
for ac_header in time.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
echo $ECHO_N "(cached) $ECHO_C" >&6
fi
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
else
# Is the header compilable?
echo "$as_me:$LINENO: checking $ac_header usability" >&5
echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
$ac_includes_default
#include <$ac_header>
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_cxx_werror_flag"
|| test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_header_compiler=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_header_compiler=no
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
echo "${ECHO_T}$ac_header_compiler" >&6
# Is the header present?
echo "$as_me:$LINENO: checking $ac_header presence" >&5
echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <$ac_header>
_ACEOF
if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
(eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } >/dev/null; then
if test -s conftest.err; then
ac_cpp_err=$ac_cxx_preproc_warn_flag
ac_cpp_err=$ac_cpp_err$ac_cxx_werror_flag
else
ac_cpp_err=
fi
else
ac_cpp_err=yes
fi
if test -z "$ac_cpp_err"; then
ac_header_preproc=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_header_preproc=no
fi
rm -f conftest.err conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
echo "${ECHO_T}$ac_header_preproc" >&6
# So? What about this header?
case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in
yes:no: )
{ echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
ac_header_preproc=yes
;;
no:yes:* )
{ echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
(
cat <<\_ASBOX
## ----------------------------------------- ##
## Report this to the package-unused lists. ##
## ----------------------------------------- ##
_ASBOX
) |
sed "s/^/$as_me: WARNING: /" >&2
;;
esac
echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
eval "$as_ac_Header=\$ac_header_preproc"
fi
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
fi
if test `eval echo '${'$as_ac_Header'}'` = yes; then
cat >>confdefs.h <<_ACEOF
#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
ac_has_time_h=yes
else
ac_has_time_h=no
fi
done
if test x"$ac_has_time_h" = x"yes"; then
echo "$as_me:$LINENO: checking for nanosleep" >&5
echo $ECHO_N "checking for nanosleep... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <time.h>
int
main ()
{
timespec ts; nanosleep(&ts, 0);
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_cxx_werror_flag"
|| test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_has_nanosleep=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_has_nanosleep=no
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_has_nanosleep" >&5
echo "${ECHO_T}$ac_has_nanosleep" >&6
fi
if test x"$ac_has_nanosleep" = x"yes"; then
cat >>confdefs.h <<\_ACEOF
#define _GLIBCXX_USE_NANOSLEEP 1
_ACEOF
fi
CXXFLAGS="$ac_save_CXXFLAGS"
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test "${ac_cv_header_locale_h+set}" = set; then
echo "$as_me:$LINENO: checking for locale.h" >&5

View File

@ -153,6 +153,9 @@ GLIBCXX_ENABLE_CLOCK_GETTIME([no])
# For gthread support
GLIBCXX_CHECK_GTHREADS
# For nanosleep support
GLIBCXX_CHECK_NANOSLEEP
AC_LC_MESSAGES
# Check for available headers.

View File

@ -63,6 +63,7 @@ std_headers = \
${std_srcdir}/streambuf \
${std_srcdir}/string \
${std_srcdir}/system_error \
${std_srcdir}/thread \
${std_srcdir}/tuple \
${std_srcdir}/type_traits \
${std_srcdir}/unordered_map \

View File

@ -317,6 +317,7 @@ std_headers = \
${std_srcdir}/streambuf \
${std_srcdir}/string \
${std_srcdir}/system_error \
${std_srcdir}/thread \
${std_srcdir}/tuple \
${std_srcdir}/type_traits \
${std_srcdir}/unordered_map \

View File

@ -0,0 +1,280 @@
// <thread> -*- C++ -*-
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file thread
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_THREAD
#define _GLIBCXX_THREAD 1
#pragma GCC system_header
#ifndef __GXX_EXPERIMENTAL_CXX0X__
# include <c++0x_warning.h>
#else
#include <chrono>
#include <exception>
#include <functional>
#include <memory>
#include <mutex>
#include <condition_variable>
#include <type_traits>
#include <cstddef>
#include <bits/functexcept.h>
#include <bits/gthr.h>
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
namespace std
{
class __thread_data_base;
typedef shared_ptr<__thread_data_base> __thread_data_ptr;
class __thread_data_base : public enable_shared_from_this<__thread_data_base>
{
public:
__thread_data_base() = default;
virtual ~__thread_data_base() = default;
virtual void __run() const = 0;
__gthread_t _M_thread_handle;
__thread_data_ptr _M_this_ptr;
mutex _M_data_mutex;
};
template<typename _Callable>
class __thread_data : public __thread_data_base
{
public:
__thread_data(_Callable&& __f)
: _M_func(std::forward<_Callable>(__f))
{ }
void __run() const
{ _M_func(); }
private:
_Callable _M_func;
};
/// thread
class thread
{
public:
// types
class id;
typedef __gthread_t native_handle_type;
// cons
thread();
template<typename _Callable>
explicit thread(_Callable __f)
: _M_thread_data(__make_thread_data(__f))
{ __start_thread(); }
template<typename _Callable, typename... _Args>
thread(_Callable&& __f, _Args&&... __args)
: _M_thread_data(__make_thread_data(std::bind(__f, __args...)))
{ __start_thread(); }
~thread();
thread(const thread&) = delete;
thread(thread&&);
thread& operator=(const thread&) = delete;
thread& operator=(thread&&);
// members
void
swap(thread&& __t);
bool
joinable() const;
void
join();
void
detach();
id
get_id() const;
native_handle_type
native_handle()
{ return _M_thread_data->_M_thread_handle; }
// static members
static unsigned hardware_concurrency();
__thread_data_ptr
_M_get_thread_data() const
{
lock_guard<mutex> __l(_M_thread_data_mutex);
return _M_thread_data;
}
private:
template<typename _Callable>
__thread_data_ptr
__make_thread_data(_Callable&& __f)
{
return __thread_data_ptr(
new __thread_data<_Callable>(std::forward<_Callable>(__f)));
}
__thread_data_ptr
__make_thread_data(void(*__f)())
{ return __thread_data_ptr(new __thread_data<void(*)()>(__f)); }
void __start_thread();
__thread_data_ptr _M_thread_data;
mutable mutex _M_thread_data_mutex;
};
inline void
swap(thread& __x, thread& __y)
{ __x.swap(__y); }
inline void
swap(thread&& __x, thread& __y)
{ __x.swap(__y); }
inline void
swap(thread& __x, thread&& __y)
{ __x.swap(__y); }
namespace this_thread
{
thread::id
get_id();
void
yield();
template<typename _Clock, typename _Duration>
void
sleep_until(const chrono::time_point<_Clock, _Duration>& __atime)
{
sleep_for(__atime - _Clock::now());
}
template<typename _Rep, typename _Period>
void
sleep_for(const chrono::duration<_Rep, _Period>& __rtime)
{
chrono::seconds __s =
chrono::duration_cast<chrono::seconds>(__rtime);
chrono::nanoseconds __ns =
chrono::duration_cast<chrono::nanoseconds>(__rtime - __s);
__gthread_time_t __ts =
{
static_cast<std::time_t>(__s.count()),
static_cast<long>(__ns.count())
};
#ifdef _GLIBCXX_USE_NANOSLEEP
::nanosleep(&__ts, 0);
#endif
}
}
/// thread::id
class thread::id
{
public:
id() : _M_thread_id() { }
private:
friend class thread;
friend thread::id this_thread::get_id();
friend bool
operator==(thread::id __x, thread::id __y)
{
return
static_cast<bool>(__gthread_equal(__x._M_thread_id, __y._M_thread_id));
}
friend bool
operator<(thread::id __x, thread::id __y)
{ return __x._M_thread_id < __y._M_thread_id; }
template<class _CharT, class _Traits>
friend basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>&& __out, thread::id __id);
id(__gthread_t __id)
: _M_thread_id(__id)
{ }
__gthread_t _M_thread_id;
};
inline bool
operator!=(thread::id __x, thread::id __y)
{ return !(__x == __y); }
inline bool
operator<=(thread::id __x, thread::id __y)
{ return !(__y < __x); }
inline bool
operator>(thread::id __x, thread::id __y)
{ return __y < __x; }
inline bool
operator>=(thread::id __x, thread::id __y)
{ return !(__x < __y); }
template<class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>&& __out, thread::id __id)
{
if(__id == thread::id())
return __out << "non-executing thread";
else
return __out << __id._M_thread_id;
}
}
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // _GLIBCXX_THREAD

View File

@ -187,6 +187,7 @@ sources = \
mutex.cc \
condition_variable.cc \
chrono.cc \
thread.cc \
${host_sources} \
${host_sources_extra}
@ -292,6 +293,11 @@ chrono.lo: chrono.cc
chrono.o: chrono.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
thread.lo: thread.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
thread.o: thread.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
if GLIBCXX_LDBL_COMPAT
# Use special rules for compatibility-ldbl.cc compilation, as we need to
# pass -mlong-double-64.

View File

@ -86,7 +86,7 @@ am__libstdc___la_SOURCES_DIST = atomic.cc bitmap_allocator.cc \
ostream-inst.cc sstream-inst.cc streambuf-inst.cc streambuf.cc \
string-inst.cc valarray-inst.cc wlocale-inst.cc \
wstring-inst.cc mutex.cc condition_variable.cc chrono.cc \
atomicity.cc codecvt_members.cc collate_members.cc \
thread.cc atomicity.cc codecvt_members.cc collate_members.cc \
ctype_members.cc messages_members.cc monetary_members.cc \
numeric_members.cc time_members.cc basic_file.cc c++locale.cc \
compatibility-ldbl.cc parallel_list.cc parallel_settings.cc
@ -111,7 +111,7 @@ am__objects_5 = atomic.lo bitmap_allocator.lo pool_allocator.lo \
ostream-inst.lo sstream-inst.lo streambuf-inst.lo streambuf.lo \
string-inst.lo valarray-inst.lo wlocale-inst.lo \
wstring-inst.lo mutex.lo condition_variable.lo chrono.lo \
$(am__objects_1) $(am__objects_4)
thread.lo $(am__objects_1) $(am__objects_4)
am_libstdc___la_OBJECTS = $(am__objects_5)
libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
@ -425,6 +425,7 @@ sources = \
mutex.cc \
condition_variable.cc \
chrono.cc \
thread.cc \
${host_sources} \
${host_sources_extra}
@ -889,6 +890,11 @@ chrono.lo: chrono.cc
chrono.o: chrono.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
thread.lo: thread.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
thread.o: thread.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
# Use special rules for compatibility-ldbl.cc compilation, as we need to
# pass -mlong-double-64.
@GLIBCXX_LDBL_COMPAT_TRUE@compatibility-ldbl.lo: compatibility-ldbl.cc

139
libstdc++-v3/src/thread.cc Normal file
View File

@ -0,0 +1,139 @@
// thread -*- C++ -*-
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <bits/move.h> // std::move
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
namespace std
{
namespace
{
extern "C"
{
void* __thread_proxy(void* __p)
{
__thread_data_base* __t = static_cast<__thread_data_base*>(__p);
__thread_data_ptr __local_thread_data = __t->_M_this_ptr;
__t->_M_this_ptr.reset();
try
{
__local_thread_data->__run();
}
catch(...)
{
std::terminate();
}
return 0;
}
}
}
thread::thread()
{ }
thread::~thread()
{
detach();
}
thread::id
thread::get_id() const
{
if(_M_thread_data)
return thread::id(_M_thread_data->_M_thread_handle);
else
return thread::id();
}
bool
thread::joinable() const
{ return get_id() != id(); }
void
thread::join()
{
if(joinable())
{
void* __r = 0;
int __e = __gthread_join(_M_thread_data->_M_thread_handle, &__r);
if(__e)
__throw_system_error(__e);
lock_guard<mutex> __lock(_M_thread_data_mutex);
_M_thread_data.reset();
}
}
void
thread::detach()
{
if(joinable())
{
int __e = __gthread_detach(_M_thread_data->_M_thread_handle);
if(__e)
__throw_system_error(__e);
lock_guard<mutex> __lock(_M_thread_data_mutex);
_M_thread_data.reset();
}
}
void
thread::swap(thread&& __t)
{
std::swap(_M_thread_data, __t._M_thread_data);
}
void
thread::__start_thread()
{
_M_thread_data->_M_this_ptr = _M_thread_data;
int __e = __gthread_create(&_M_thread_data->_M_thread_handle,
&__thread_proxy, _M_thread_data.get());
if(__e)
__throw_system_error(__e);
}
namespace this_thread
{
thread::id
get_id()
{ return thread::id(__gthread_self()); }
void
yield()
{ __gthread_yield(); }
}
}
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1

View File

@ -96,8 +96,8 @@
#include <array>
#include <bitset>
#include <chrono>
#include <condition_variable>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <fstream>
@ -128,6 +128,7 @@
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeinfo>
#include <type_traits>

View File

@ -95,6 +95,7 @@
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <fstream>
@ -110,6 +111,7 @@
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
@ -123,6 +125,7 @@
#include <stdexcept>
#include <streambuf>
#include <string>
#include <thread>
#include <tuple>
#include <typeinfo>
#include <type_traits>
@ -207,6 +210,7 @@
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <fstream>
@ -236,6 +240,7 @@
#include <stdexcept>
#include <streambuf>
#include <string>
#include <thread>
#include <tuple>
#include <typeinfo>
#include <type_traits>

View File

@ -0,0 +1,26 @@
// { dg-do compile }
// { dg-options "-std=gnu++98" }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <thread> // { dg-excess-errors "In file included from" }
// { dg-error "upcoming ISO" "" { target *-*-* } 36 }

View File

@ -0,0 +1,31 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <thread>
void test01()
{
typedef std::thread t_t;
using namespace std::this_thread;
}

View File

@ -0,0 +1,67 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <bits/move.h> // std::move
#include <testsuite_hooks.h>
void f() { }
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::thread t1(f);
std::thread::id t1_id = t1.get_id();
std::thread t2;
t2.swap(std::move(t1));
VERIFY( t1.get_id() == std::thread::id() );
VERIFY( t2.get_id() == t1_id );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,115 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <bits/move.h> // std::move
#include <testsuite_hooks.h>
void f() { }
void test01()
{
try
{
std::thread t1(f);
std::thread::id t1_id = t1.get_id();
std::thread t2;
std::swap(t1, t2);
VERIFY( t1.get_id() == std::thread::id() );
VERIFY( t2.get_id() == t1_id );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
}
void test02()
{
try
{
std::thread t1(f);
std::thread::id t1_id = t1.get_id();
std::thread t2;
std::swap(std::move(t1), t2);
VERIFY( t2.get_id() == t1_id );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
}
void test03()
{
try
{
std::thread t1(f);
std::thread::id t1_id = t1.get_id();
std::thread t2;
std::swap(t2, std::move(t1));
VERIFY( t2.get_id() == t1_id );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
}
int main()
{
test01();
test02();
test03();
return 0;
}

View File

@ -0,0 +1,58 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::thread t;
VERIFY( !t.joinable() );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,74 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <utility> // std::ref
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
void
free_function(std::thread::id& id)
{
id = std::this_thread::get_id();
}
void test02()
{
bool test __attribute__((unused)) = true;
try
{
std::thread::id t1_id1;
std::thread t1(free_function, std::ref(t1_id1));
std::thread::id t1_id2 = t1.get_id();
VERIFY( t1.joinable() );
t1.join();
VERIFY( !t1.joinable() );
VERIFY( t1_id1 == t1_id2 );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
}
int main()
{
test02();
return 0;
}

View File

@ -0,0 +1,98 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <functional> // std::unary_function
#include <utility> // std::ref
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
struct copyable : public std::unary_function<std::thread::id&, void>
{
copyable() = default;
~copyable() = default;
copyable(const copyable& c)
{ ++copy_count; }
void operator()(std::thread::id& id) const
{
id = std::this_thread::get_id();
}
static int copy_count;
};
int copyable::copy_count = 0;
void test03()
{
bool test __attribute__((unused)) = true;
try
{
std::thread::id t1_id1;
copyable c1;
std::thread t1(std::ref(c1), std::ref(t1_id1));
std::thread::id t1_id2 = t1.get_id();
VERIFY( t1.joinable() );
t1.join();
VERIFY( !t1.joinable() );
VERIFY( t1_id1 == t1_id2 );
VERIFY( copyable::copy_count == 0 );
std::thread::id t2_id1;
copyable c2;
std::thread t2(c2, std::ref(t2_id1));
std::thread::id t2_id2 = t2.get_id();
VERIFY( t2.joinable() );
t2.join();
VERIFY( !t2.joinable() );
VERIFY( t2_id1 == t2_id2 );
VERIFY( copyable::copy_count > 0 );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,91 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <functional> // std::unary_function
#include <utility> // std::ref, std::cref
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
struct noncopyable : std::unary_function<std::thread::id&, void>
{
noncopyable() = default;
~noncopyable() = default;
noncopyable(const noncopyable&) = delete;
noncopyable& operator=(const noncopyable&) = delete;
void operator()(std::thread::id& id) const
{
id = std::this_thread::get_id();
}
};
void test03()
{
bool test __attribute__((unused)) = true;
try
{
std::thread::id t1_id1;
noncopyable nc1;
std::thread t1(std::ref(nc1), std::ref(t1_id1));
std::thread::id t1_id2 = t1.get_id();
VERIFY( t1.joinable() );
t1.join();
VERIFY( !t1.joinable() );
VERIFY( t1_id1 == t1_id2 );
std::thread::id t2_id1;
noncopyable nc2;
std::thread t2(std::cref(nc2), std::ref(t2_id1));
std::thread::id t2_id2 = t2.get_id();
VERIFY( t2.joinable() );
t2.join();
VERIFY( !t2.joinable() );
VERIFY( t2_id1 == t2_id2 );
}
catch(const std::system_error&)
{
VERIFY( false );
}
catch(...)
{
VERIFY( false );
}
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,62 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
void f() { }
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::thread t(f);
VERIFY( t.joinable() );
t.join();
VERIFY( !t.joinable() );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,62 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
void f() { }
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::thread t(f);
VERIFY( t.joinable() );
t.detach();
VERIFY( !t.joinable() );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,62 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
void f() { }
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::thread t(f);
VERIFY( t.get_id() != std::thread::id() );
t.join();
VERIFY( t.get_id() == std::thread::id() );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,58 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::thread::id id = std::this_thread::get_id();
VERIFY( id != std::thread::id() );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,57 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::this_thread::yield();
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,72 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// { dg-require-nanosleep "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <chrono>
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
namespace chr = std::chrono;
void foo()
{
chr::system_clock::time_point begin = chr::system_clock::now();
chr::microseconds ms(500);
std::this_thread::sleep_for(ms);
VERIFY( (chr::system_clock::now() - begin) >= ms );
}
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::thread t(foo);
t.join();
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,72 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// { dg-require-nanosleep "" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <chrono>
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
namespace chr = std::chrono;
void foo()
{
chr::system_clock::time_point begin = chr::system_clock::now();
chr::microseconds ms(500);
std::this_thread::sleep_until(chr::system_clock::now() + ms);
VERIFY( (chr::system_clock::now() - begin) >= ms );
}
int main()
{
bool test __attribute__((unused)) = true;
try
{
std::thread t(foo);
t.join();
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -115,3 +115,12 @@ proc dg-require-gthreads { args } {
}
return
}
proc dg-require-nanosleep { args } {
if { ![ check_v3_target_nanosleep ] } {
upvar dg-do-what dg-do-what
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
return
}
return
}

View File

@ -1178,3 +1178,61 @@ proc check_v3_target_gthreads { } {
verbose "check_v3_target_gthreads: $et_gthreads" 2
return $et_gthreads
}
proc check_v3_target_nanosleep { } {
global cxxflags
global DEFAULT_CXXFLAGS
global et_nanosleep
global tool
if { ![info exists et_nanosleep_target_name] } {
set et_nanosleep_target_name ""
}
# If the target has changed since we set the cached value, clear it.
set current_target [current_target_name]
if { $current_target != $et_nanosleep_target_name } {
verbose "check_v3_target_nanosleep: `$et_nanosleep_target_name'" 2
set et_nanosleep_target_name $current_target
if [info exists et_nanosleep] {
verbose "check_v3_target_nanosleep: removing cached result" 2
unset et_nanosleep
}
}
if [info exists et_nanosleep] {
verbose "check_v3_target_nanosleep: using cached result" 2
} else {
set et_nanosleep 0
# Set up and compile a C++0x test program that depends
# on the nanosleep facilities to be available.
set src nanosleep[pid].cc
set exe nanosleep[pid].exe
set f [open $src "w"]
puts $f "#include <bits/c++config.h>"
puts $f "int main()"
puts $f "#ifdef _GLIBCXX_USE_NANOSLEEP"
puts $f "{ return 0; }"
puts $f "#endif"
close $f
set cxxflags_saved $cxxflags
set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
set lines [v3_target_compile $src $exe executable ""]
set cxxflags $cxxflags_saved
file delete $src
if [string match "" $lines] {
# No error message, compilation succeeded.
set et_nanosleep 1
} else {
verbose "check_v3_target_nanosleep: compilation failed" 2
}
}
verbose "check_v3_target_nanosleep: $et_nanosleep" 2
return $et_nanosleep
}