From: Jonathan Wakely Date: Sun, 21 Jun 2009 14:02:09 +0000 (+0000) Subject: future: New. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c910ceff6a0533e34889ef4aa86d19e42cbff123;p=gcc.git future: New. 2009-06-21 Jonathan Wakely * include/std/future: New. * include/Makefile.am: Add. * include/Makefile.in: Regenerate. * src/future.cc: New. * src/Makefile.am: Add. * src/Makefile.in: Regenerate. * config/abi/pre/gnu.ver: Add export. * testsuite/30_threads/headers/future/std_c++0x_neg.cc: New. * testsuite/30_threads/headers/future/types_std_c++0x.cc: New. * testsuite/30_threads/packaged_task/cons/1.cc: New. * testsuite/30_threads/packaged_task/cons/2.cc: New. * testsuite/30_threads/packaged_task/cons/assign_neg.cc: New. * testsuite/30_threads/packaged_task/cons/copy_neg.cc: New. * testsuite/30_threads/packaged_task/cons/move_assign.cc: New. * testsuite/30_threads/packaged_task/cons/move.cc: New. * testsuite/30_threads/packaged_task/members/boolconv.cc: New. * testsuite/30_threads/packaged_task/members/get_future.cc: New. * testsuite/30_threads/packaged_task/members/get_future2.cc: New. * testsuite/30_threads/packaged_task/members/invoke.cc: New. * testsuite/30_threads/packaged_task/members/invoke2.cc: New. * testsuite/30_threads/packaged_task/members/invoke3.cc: New. * testsuite/30_threads/packaged_task/members/invoke4.cc: New. * testsuite/30_threads/packaged_task/members/invoke5.cc: New. * testsuite/30_threads/packaged_task/members/reset.cc: New. * testsuite/30_threads/packaged_task/members/reset2.cc: New. * testsuite/30_threads/packaged_task/members/swap.cc: New. * testsuite/30_threads/packaged_task/requirements/ explicit_instantiation.cc: New. * testsuite/30_threads/promise/cons/1.cc: New. * testsuite/30_threads/promise/cons/assign_neg.cc: New. * testsuite/30_threads/promise/cons/copy_neg.cc: New. * testsuite/30_threads/promise/cons/move_assign.cc: New. * testsuite/30_threads/promise/cons/move.cc: New. * testsuite/30_threads/promise/members/get_future.cc: New. * testsuite/30_threads/promise/members/get_future2.cc: New. * testsuite/30_threads/promise/members/set_exception.cc: New. * testsuite/30_threads/promise/members/set_exception2.cc: New. * testsuite/30_threads/promise/members/set_value.cc: New. * testsuite/30_threads/promise/members/set_value2.cc: New. * testsuite/30_threads/promise/members/set_value3.cc: New. * testsuite/30_threads/promise/members/swap.cc: New. * testsuite/30_threads/promise/requirements/ explicit_instantiation.cc: New. * testsuite/30_threads/shared_future/cons/assign_neg.cc: New. * testsuite/30_threads/shared_future/cons/copy.cc: New. * testsuite/30_threads/shared_future/cons/default_neg.cc: New. * testsuite/30_threads/shared_future/cons/move.cc: New. * testsuite/30_threads/shared_future/members/get.cc: New. * testsuite/30_threads/shared_future/members/get2.cc: New. * testsuite/30_threads/shared_future/members/has_exception.cc: New. * testsuite/30_threads/shared_future/members/has_value.cc: New. * testsuite/30_threads/shared_future/members/is_ready.cc: New. * testsuite/30_threads/shared_future/members/wait.cc: New. * testsuite/30_threads/shared_future/members/wait_for.cc: New. * testsuite/30_threads/shared_future/members/wait_until.cc: New. * testsuite/30_threads/shared_future/requirements/ explicit_instantiation.cc: New. * testsuite/30_threads/unique_future/cons/assign_neg.cc: New. * testsuite/30_threads/unique_future/cons/copy_neg.cc: New. * testsuite/30_threads/unique_future/cons/default_neg.cc: New. * testsuite/30_threads/unique_future/cons/move.cc: New. * testsuite/30_threads/unique_future/members/get.cc: New. * testsuite/30_threads/unique_future/members/get2.cc: New. * testsuite/30_threads/unique_future/members/has_exception.cc: New. * testsuite/30_threads/unique_future/members/has_value.cc: New. * testsuite/30_threads/unique_future/members/is_ready.cc: New. * testsuite/30_threads/unique_future/members/wait.cc: New. * testsuite/30_threads/unique_future/members/wait_for.cc: New. * testsuite/30_threads/unique_future/members/wait_until.cc: New. * testsuite/30_threads/unique_future/requirements/ explicit_instantiation.cc: New. * testsuite/performance/30_threads/future/polling.cc: New. From-SVN: r148765 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8e7277447ca..cefde03746f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,78 @@ +2009-06-21 Jonathan Wakely + + * include/std/future: New. + * include/Makefile.am: Add. + * include/Makefile.in: Regenerate. + * src/future.cc: New. + * src/Makefile.am: Add. + * src/Makefile.in: Regenerate. + * config/abi/pre/gnu.ver: Add export. + * testsuite/30_threads/headers/future/std_c++0x_neg.cc: New. + * testsuite/30_threads/headers/future/types_std_c++0x.cc: New. + * testsuite/30_threads/packaged_task/cons/1.cc: New. + * testsuite/30_threads/packaged_task/cons/2.cc: New. + * testsuite/30_threads/packaged_task/cons/assign_neg.cc: New. + * testsuite/30_threads/packaged_task/cons/copy_neg.cc: New. + * testsuite/30_threads/packaged_task/cons/move_assign.cc: New. + * testsuite/30_threads/packaged_task/cons/move.cc: New. + * testsuite/30_threads/packaged_task/members/boolconv.cc: New. + * testsuite/30_threads/packaged_task/members/get_future.cc: New. + * testsuite/30_threads/packaged_task/members/get_future2.cc: New. + * testsuite/30_threads/packaged_task/members/invoke.cc: New. + * testsuite/30_threads/packaged_task/members/invoke2.cc: New. + * testsuite/30_threads/packaged_task/members/invoke3.cc: New. + * testsuite/30_threads/packaged_task/members/invoke4.cc: New. + * testsuite/30_threads/packaged_task/members/invoke5.cc: New. + * testsuite/30_threads/packaged_task/members/reset.cc: New. + * testsuite/30_threads/packaged_task/members/reset2.cc: New. + * testsuite/30_threads/packaged_task/members/swap.cc: New. + * testsuite/30_threads/packaged_task/requirements/ + explicit_instantiation.cc: New. + * testsuite/30_threads/promise/cons/1.cc: New. + * testsuite/30_threads/promise/cons/assign_neg.cc: New. + * testsuite/30_threads/promise/cons/copy_neg.cc: New. + * testsuite/30_threads/promise/cons/move_assign.cc: New. + * testsuite/30_threads/promise/cons/move.cc: New. + * testsuite/30_threads/promise/members/get_future.cc: New. + * testsuite/30_threads/promise/members/get_future2.cc: New. + * testsuite/30_threads/promise/members/set_exception.cc: New. + * testsuite/30_threads/promise/members/set_exception2.cc: New. + * testsuite/30_threads/promise/members/set_value.cc: New. + * testsuite/30_threads/promise/members/set_value2.cc: New. + * testsuite/30_threads/promise/members/set_value3.cc: New. + * testsuite/30_threads/promise/members/swap.cc: New. + * testsuite/30_threads/promise/requirements/ + explicit_instantiation.cc: New. + * testsuite/30_threads/shared_future/cons/assign_neg.cc: New. + * testsuite/30_threads/shared_future/cons/copy.cc: New. + * testsuite/30_threads/shared_future/cons/default_neg.cc: New. + * testsuite/30_threads/shared_future/cons/move.cc: New. + * testsuite/30_threads/shared_future/members/get.cc: New. + * testsuite/30_threads/shared_future/members/get2.cc: New. + * testsuite/30_threads/shared_future/members/has_exception.cc: New. + * testsuite/30_threads/shared_future/members/has_value.cc: New. + * testsuite/30_threads/shared_future/members/is_ready.cc: New. + * testsuite/30_threads/shared_future/members/wait.cc: New. + * testsuite/30_threads/shared_future/members/wait_for.cc: New. + * testsuite/30_threads/shared_future/members/wait_until.cc: New. + * testsuite/30_threads/shared_future/requirements/ + explicit_instantiation.cc: New. + * testsuite/30_threads/unique_future/cons/assign_neg.cc: New. + * testsuite/30_threads/unique_future/cons/copy_neg.cc: New. + * testsuite/30_threads/unique_future/cons/default_neg.cc: New. + * testsuite/30_threads/unique_future/cons/move.cc: New. + * testsuite/30_threads/unique_future/members/get.cc: New. + * testsuite/30_threads/unique_future/members/get2.cc: New. + * testsuite/30_threads/unique_future/members/has_exception.cc: New. + * testsuite/30_threads/unique_future/members/has_value.cc: New. + * testsuite/30_threads/unique_future/members/is_ready.cc: New. + * testsuite/30_threads/unique_future/members/wait.cc: New. + * testsuite/30_threads/unique_future/members/wait_for.cc: New. + * testsuite/30_threads/unique_future/members/wait_until.cc: New. + * testsuite/30_threads/unique_future/requirements/ + explicit_instantiation.cc: New. + * testsuite/performance/30_threads/future/polling.cc: New. + 2009-06-20 Paolo Carlini * Revert last Change. diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 240e7bcf09b..3a24dc9fb16 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -964,6 +964,9 @@ GLIBCXX_3.4.12 { _ZSt27__set_once_functor_lock_ptrPSt11unique_lockISt5mutexE; _ZSt16__get_once_mutexv; + # future + _ZSt15future_category; + } GLIBCXX_3.4.11; # Symbols in the support library (libsupc++) have their own tag. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 6a9c4f09ed4..b0fc483f20b 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -38,6 +38,7 @@ std_headers = \ ${std_srcdir}/forward_list \ ${std_srcdir}/fstream \ ${std_srcdir}/functional \ + ${std_srcdir}/future \ ${std_srcdir}/iomanip \ ${std_srcdir}/ios \ ${std_srcdir}/iosfwd \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 4ac2739cb43..bba451f7db6 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -304,6 +304,7 @@ std_headers = \ ${std_srcdir}/forward_list \ ${std_srcdir}/fstream \ ${std_srcdir}/functional \ + ${std_srcdir}/future \ ${std_srcdir}/iomanip \ ${std_srcdir}/ios \ ${std_srcdir}/iosfwd \ diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future new file mode 100644 index 00000000000..c485b9614a1 --- /dev/null +++ b/libstdc++-v3/include/std/future @@ -0,0 +1,925 @@ +// -*- C++ -*- + +// Copyright (C) 2009 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file future + * This is a Standard C++ Library header. + */ + +#ifndef _GLIBCXX_FUTURE +#define _GLIBCXX_FUTURE 1 + +#pragma GCC system_header + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include +#else + +#include +#include +#include +#include +#include +#include +#include + +#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \ + && defined(_GLIBCXX_ATOMIC_BUILTINS_4) + +namespace std +{ + /** + * @defgroup futures Futures + * @ingroup concurrency + * + * Classes for futures support. + * @{ + */ + + /// Error code for futures + enum class future_errc + { broken_promise, future_already_retrieved, promise_already_satisfied }; + + // TODO: requires concepts + // concept_map ErrorCodeEnum { } + template<> + struct is_error_code_enum : public true_type { }; + + /// Points to a statically-allocated object derived from error_category. + extern const error_category* const future_category; + + // TODO: requires constexpr + inline error_code make_error_code(future_errc __errc) + { return error_code(static_cast(__errc), *future_category); } + + // TODO: requires constexpr + inline error_condition make_error_condition(future_errc __errc) + { return error_condition(static_cast(__errc), *future_category); } + + /// Exception type thrown by futures. + class future_error : public logic_error + { + public: + explicit future_error(future_errc __ec) + : logic_error("std::future_error"), _M_code(make_error_code(__ec)) + { } + + const error_code& code() const throw() { return _M_code; } + + const char* what() const throw() { return _M_code.message().c_str(); } + + private: + error_code _M_code; + }; + + // Holds the result of a future + struct _Future_result_base + { + _Future_result_base() = default; + _Future_result_base(const _Future_result_base&) = delete; + _Future_result_base& operator=(const _Future_result_base&) = delete; + + exception_ptr _M_error; + + // _M_destroy() allows derived classes to control deallocation, + // which will be needed when allocator support is added to promise. + // See http://gcc.gnu.org/ml/libstdc++/2009-06/msg00032.html + virtual void _M_destroy() = 0; + struct _Deleter + { + void operator()(_Future_result_base* __fr) const { __fr->_M_destroy(); } + }; + + protected: + ~_Future_result_base() = default; + }; + + // TODO: use template alias when available + /* + template + using _Future_ptr = unique_ptr<_Res, _Future_result_base::_Deleter>; + */ + template + struct _Future_ptr + { + typedef unique_ptr<_Res, _Future_result_base::_Deleter> type; + }; + + // State shared between a promise and one or more associated futures. + class _Future_state + { + typedef _Future_ptr<_Future_result_base>::type _Future_ptr_type; + + public: + _Future_state() : _M_result(), _M_retrieved(false) { } + + _Future_state(const _Future_state&) = delete; + _Future_state& operator=(const _Future_state&) = delete; + + bool + is_ready() + { return _M_get() != 0; } + + bool + has_exception() + { + _Future_result_base* const __res = _M_get(); + return __res && !(__res->_M_error == 0); + } + + bool + has_value() + { + _Future_result_base* const __res = _M_get(); + return __res && (__res->_M_error == 0); + } + + _Future_result_base& + wait() + { + unique_lock __lock(_M_mutex); + if (!_M_ready()) + _M_cond.wait(__lock, std::bind(&_Future_state::_M_ready, this)); + return *_M_result; + } + + template + bool + wait_for(const chrono::duration<_Rep, _Period>& __rel) + { + unique_lock __lock(_M_mutex); + return _M_ready() || _M_cond.wait_for(__lock, __rel, + std::bind(&_Future_state::_M_ready, this)); + } + + template + bool + wait_until(const chrono::time_point<_Clock, _Duration>& __abs) + { + unique_lock __lock(_M_mutex); + return _M_ready() || _M_cond.wait_until(__lock, __abs, + std::bind(&_Future_state::_M_ready, this)); + } + + void + _M_set_result(_Future_ptr_type __res) + { + { + lock_guard __lock(_M_mutex); + if (_M_ready()) + throw future_error(future_errc::promise_already_satisfied); + _M_result.swap(__res); + } + _M_cond.notify_all(); + } + + void + _M_break_promise(_Future_ptr_type __res) + { + if (static_cast(__res)) + { + __res->_M_error + = std::copy_exception(future_error(future_errc::broken_promise)); + { + lock_guard __lock(_M_mutex); + _M_result.swap(__res); + } + _M_cond.notify_all(); + } + } + + // called when this object is passed to a unique_future + void + _M_set_retrieved_flag() + { + if (_M_retrieved.test_and_set()) + throw future_error(future_errc::future_already_retrieved); + } + + private: + _Future_result_base* + _M_get() + { + lock_guard __lock(_M_mutex); + return _M_result.get(); + } + + bool _M_ready() const { return static_cast(_M_result); } + + _Future_ptr_type _M_result; + mutex _M_mutex; + condition_variable _M_cond; + atomic_flag _M_retrieved; + }; + + // workaround for CWG issue 664 and c++/34022 + template::value> + struct _Move_future_result + { + typedef _Result&& __rval_type; + static _Result&& _S_move(_Result& __res) { return std::move(__res); } + }; + + // specialization for scalar types returns rvalue not rvalue-reference + template + struct _Move_future_result<_Result, true> + { + typedef _Result __rval_type; + static _Result _S_move(_Result __res) { return __res; } + }; + + template + struct _Future_result : _Future_result_base + { + _Future_result() : _M_initialized() { } + + ~_Future_result() + { + if (_M_initialized) + _M_value().~_Result(); + } + + // return lvalue, future will add const or rvalue-reference + _Result& _M_value() + { return *static_cast<_Result*>(_M_addr()); } + + void + _M_set(const _Result& __res) + { + ::new (_M_addr()) _Result(__res); + _M_initialized = true; + } + + void + _M_set(_Result&& __res) + { + typedef _Move_future_result<_Result> _Mover; + ::new (_M_addr()) _Result(_Mover::_S_move(__res)); + _M_initialized = true; + } + + private: + void _M_destroy() { delete this; } + + void* _M_addr() { return static_cast(&_M_storage); } + + typename aligned_storage::value>::type _M_storage; + bool _M_initialized; + }; + + template + struct _Future_result<_Result&> : _Future_result_base + { + _Future_result() : _M_value_ptr() { } + + _Result* _M_value_ptr; + + void _M_destroy() { delete this; } + }; + + template<> + struct _Future_result : _Future_result_base + { + void _M_destroy() { delete this; } + }; + + /// unique_future + template + class unique_future; + + /// shared_future + template + class shared_future; + + // common implementation for unique_future and shared_future + template + class _Future_impl + { + public: + // disable copying + _Future_impl(const _Future_impl&) = delete; + _Future_impl& operator=(const _Future_impl&) = delete; + + // functions to check state and wait for ready + bool is_ready() const { return this->_M_state->is_ready(); } + + bool has_exception() const { return this->_M_state->has_exception(); } + + bool has_value() const { return this->_M_state->has_value(); } + + void wait() const { this->_M_state->wait(); } + + template + bool + wait_for(const chrono::duration<_Rep, _Period>& __rel) const + { return this->_M_state->wait_for(__rel); } + + template + bool + wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const + { return this->_M_state->wait_until(__abs); } + + protected: + // wait for the state to be ready and rethrow any stored exception + _Future_result<_Result>& + _M_get_result() + { + _Future_result_base& __res = this->_M_state->wait(); + if (!(__res._M_error == 0)) + rethrow_exception(__res._M_error); + return static_cast<_Future_result<_Result>&>(__res); + } + + typedef shared_ptr<_Future_state> _State_ptr; + + // construction of a unique_future by promise::get_future() + explicit + _Future_impl(const _State_ptr& __state) + : _M_state(__state) + { + if (static_cast(this->_M_state)) + this->_M_state->_M_set_retrieved_flag(); + else + throw future_error(future_errc::future_already_retrieved); + } + + // copy construction from a shared_future + explicit + _Future_impl(const shared_future<_Result>&); + + // move construction from a unique_future + explicit + _Future_impl(unique_future<_Result>&&); + + _State_ptr _M_state; + }; + + /// promise + template + class promise; + + // primary template for unique_future + template + class unique_future : public _Future_impl<_Result> + { + typedef _Move_future_result<_Result> _Mover; + + public: + /// Move constructor + unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { } + + // disable copying + unique_future(const unique_future&) = delete; + unique_future& operator=(const unique_future&) = delete; + + // retrieving the value + typename _Mover::__rval_type + get() + { return _Mover::_S_move(this->_M_get_result()._M_value()); } + + private: + typedef _Future_impl<_Result> _Base_type; + typedef typename _Base_type::_State_ptr _State_ptr; + + friend class promise<_Result>; + + explicit + unique_future(const _State_ptr& __state) : _Base_type(__state) { } + }; + + // partial specialization for unique_future + template + class unique_future<_Result&> : public _Future_impl<_Result&> + { + public: + /// Move constructor + unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { } + + // disable copying + unique_future(const unique_future&) = delete; + unique_future& operator=(const unique_future&) = delete; + + // retrieving the value + _Result& get() { return *this->_M_get_result()._M_value_ptr; } + + private: + typedef _Future_impl<_Result&> _Base_type; + typedef typename _Base_type::_State_ptr _State_ptr; + + friend class promise<_Result&>; + + explicit + unique_future(const _State_ptr& __state) : _Base_type(__state) { } + }; + + // specialization for unique_future + template<> + class unique_future : public _Future_impl + { + public: + /// Move constructor + unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { } + + // disable copying + unique_future(const unique_future&) = delete; + unique_future& operator=(const unique_future&) = delete; + + // retrieving the value + void get() { this->_M_get_result(); } + + private: + typedef _Future_impl _Base_type; + typedef _Base_type::_State_ptr _State_ptr; + + friend class promise; + + explicit + unique_future(const _State_ptr& __state) : _Base_type(__state) { } + }; + + // primary template for unique_future + template + class shared_future : public _Future_impl<_Result> + { + public: + /// Copy constructor + shared_future(const shared_future& __sf) : _Base_type(__sf) { } + + /// Construct from a unique_future rvalue + shared_future(unique_future<_Result>&& __uf) + : _Base_type(std::move(__uf)) + { } + + shared_future& operator=(const shared_future&) = delete; + + // retrieving the value + const _Result& + get() + { return this->_M_get_result()._M_value(); } + + private: + typedef _Future_impl<_Result> _Base_type; + }; + + // partial specialization for shared_future + template + class shared_future<_Result&> : public _Future_impl<_Result&> + { + public: + /// Copy constructor + shared_future(const shared_future& __sf) : _Base_type(__sf) { } + + /// Construct from a unique_future rvalue + shared_future(unique_future<_Result&>&& __uf) + : _Base_type(std::move(__uf)) + { } + + shared_future& operator=(const shared_future&) = delete; + + // retrieving the value + _Result& get() { return *this->_M_get_result()._M_value_ptr; } + + private: + typedef _Future_impl<_Result&> _Base_type; + }; + + // specialization for shared_future + template<> + class shared_future : public _Future_impl + { + public: + /// Copy constructor + shared_future(const shared_future& __sf) : _Base_type(__sf) { } + + /// Construct from a unique_future rvalue + shared_future(unique_future&& __uf) + : _Base_type(std::move(__uf)) + { } + + shared_future& operator=(const shared_future&) = delete; + + // retrieving the value + void get() { this->_M_get_result(); } + + private: + typedef _Future_impl _Base_type; + }; + + // now we can define the protected _Future_impl constructors + + template + _Future_impl<_Result>::_Future_impl(const shared_future<_Result>& __sf) + : _M_state(__sf._M_state) + { } + + template + _Future_impl<_Result>::_Future_impl(unique_future<_Result>&& __uf) + : _M_state(std::move(__uf._M_state)) + { } + + template class packaged_task; // undefined + + // primary template for promise + template + class promise + { + public: + promise() + : _M_future(std::make_shared<_Future_state>()), + _M_storage(new _Future_result<_Result>()) + { } + + promise(promise&& __rhs) + : _M_future(std::move(__rhs._M_future)), + _M_storage(std::move(__rhs._M_storage)) + { } + + // TODO: requires allocator concepts + /* + template + promise(allocator_arg_t, const _Allocator& __a); + + template + promise(allocator_arg_t, const _Allocator&, promise&& __rhs); + */ + + promise(const promise&) = delete; + + ~promise() + { + if (static_cast(_M_future) && !_M_future.unique()) + _M_future->_M_break_promise(std::move(_M_storage)); + } + + // assignment + promise& + operator=(promise&& __rhs) + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + + promise& operator=(const promise&) = delete; + + void + swap(promise& __rhs) + { + _M_future.swap(__rhs._M_future); + _M_storage.swap(__rhs._M_storage); + } + + // retrieving the result + unique_future<_Result> + get_future() + { return unique_future<_Result>(_M_future); } + + // setting the result + void + set_value(const _Result& __r) + { + if (!_M_satisfied()) + _M_storage->_M_set(__r); + _M_future->_M_set_result(std::move(_M_storage)); + } + + void + set_value(_Result&& __r) + { + if (!_M_satisfied()) + _M_storage->_M_set(_Mover::_S_move(__r)); + _M_future->_M_set_result(std::move(_M_storage)); + } + + void + set_exception(exception_ptr __p) + { + if (!_M_satisfied()) + _M_storage->_M_error = __p; + _M_future->_M_set_result(std::move(_M_storage)); + } + + private: + template friend class packaged_task; + typedef _Move_future_result<_Result> _Mover; + bool _M_satisfied() { return !static_cast(_M_storage); } + shared_ptr<_Future_state> _M_future; + typename _Future_ptr<_Future_result<_Result>>::type _M_storage; + }; + + // partial specialization for promise + template + class promise<_Result&> + { + public: + promise() + : _M_future(std::make_shared<_Future_state>()), + _M_storage(new _Future_result<_Result&>()) + { } + + promise(promise&& __rhs) + : _M_future(std::move(__rhs._M_future)), + _M_storage(std::move(__rhs._M_storage)) + { } + + // TODO: requires allocator concepts + /* + template + promise(allocator_arg_t, const _Allocator& __a); + + template + promise(allocator_arg_t, const _Allocator&, promise&& __rhs); + */ + + promise(const promise&) = delete; + + ~promise() + { + if (static_cast(_M_future) && !_M_future.unique()) + _M_future->_M_break_promise(std::move(_M_storage)); + } + + // assignment + promise& + operator=(promise&& __rhs) + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + + promise& operator=(const promise&) = delete; + + void + swap(promise& __rhs) + { + _M_future.swap(__rhs._M_future); + _M_storage.swap(__rhs._M_storage); + } + + // retrieving the result + unique_future<_Result&> + get_future() + { return unique_future<_Result&>(_M_future); } + + // setting the result + void + set_value(_Result& __r) + { + if (!_M_satisfied()) + _M_storage->_M_value_ptr = &__r; + _M_future->_M_set_result(std::move(_M_storage)); + } + + void + set_exception(exception_ptr __p) + { + if (!_M_satisfied()) + _M_storage->_M_error = __p; + _M_future->_M_set_result(std::move(_M_storage)); + } + + private: + template friend class packaged_task; + bool _M_satisfied() { return !static_cast(_M_storage); } + shared_ptr<_Future_state> _M_future; + typename _Future_ptr<_Future_result<_Result&>>::type _M_storage; + }; + + // specialization for promise + template<> + class promise + { + public: + promise() + : _M_future(std::make_shared<_Future_state>()), + _M_storage(new _Future_result()) + { } + + promise(promise&& __rhs) + : _M_future(std::move(__rhs._M_future)), + _M_storage(std::move(__rhs._M_storage)) + { } + + // TODO: requires allocator concepts + /* + template + promise(allocator_arg_t, const _Allocator& __a); + + template + promise(allocator_arg_t, const _Allocator&, promise&& __rhs); + */ + + promise(const promise&) = delete; + + ~promise() + { + if (static_cast(_M_future) && !_M_future.unique()) + _M_future->_M_break_promise(std::move(_M_storage)); + } + + // assignment + promise& + operator=(promise&& __rhs) + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + + promise& operator=(const promise&) = delete; + + void + swap(promise& __rhs) + { + _M_future.swap(__rhs._M_future); + _M_storage.swap(__rhs._M_storage); + } + + // retrieving the result + unique_future + get_future() + { return unique_future(_M_future); } + + // setting the result + void + set_value() + { + _M_future->_M_set_result(std::move(_M_storage)); + } + + void + set_exception(exception_ptr __p) + { + if (!_M_satisfied()) + _M_storage->_M_error = __p; + _M_future->_M_set_result(std::move(_M_storage)); + } + + private: + template friend class packaged_task; + bool _M_satisfied() { return !static_cast(_M_storage); } + shared_ptr<_Future_state> _M_future; + _Future_ptr<_Future_result>::type _M_storage; + }; + + // TODO: requires allocator concepts + /* + template + concept_map UsesAllocator, Alloc> + { + typedef Alloc allocator_type; + } + */ + + template + struct _Run_task + { + static void + _S_run(promise<_Result>& __p, function<_Result(_ArgTypes...)>& __f, + _ArgTypes... __args) + { + __p.set_value(__f(std::forward<_ArgTypes>(__args)...)); + } + }; + + // specialization used by packaged_task + template + struct _Run_task + { + static void + _S_run(promise& __p, function& __f, + _ArgTypes... __args) + { + __f(std::forward<_ArgTypes>(__args)...); + __p.set_value(); + } + }; + + template + class packaged_task<_Result(_ArgTypes...)> + { + public: + typedef _Result result_type; + + // construction and destruction + packaged_task() { } + + template + explicit + packaged_task(const _Fn& __fn) : _M_task(__fn) { } + + template + explicit + packaged_task(_Fn&& __fn) : _M_task(std::move(__fn)) { } + + explicit + packaged_task(_Result(*__fn)(_ArgTypes...)) : _M_task(__fn) { } + + // TODO: requires allocator concepts + /* + template + explicit + packaged_task(allocator_arg_t __tag, const _Allocator& __a, _Fn __fn) + : _M_task(__tag, __a, __fn), _M_promise(__tag, __a) + { } + + template + explicit + packaged_task(allocator_arg_t __tag, const _Allocator& __a, _Fn&& __fn) + : _M_task(__tag, __a, std::move(__fn)), _M_promise(__tag, __a) + { } + */ + + ~packaged_task() = default; + + // no copy + packaged_task(packaged_task&) = delete; + packaged_task& operator=(packaged_task&) = delete; + + // move support + packaged_task(packaged_task&& __other) + { this->swap(__other); } + + packaged_task& operator=(packaged_task&& __other) + { + packaged_task(std::move(__other)).swap(*this); + return *this; + } + + void + swap(packaged_task& __other) + { + _M_task.swap(__other._M_task); + _M_promise.swap(__other._M_promise); + } + + explicit operator bool() const { return static_cast(_M_task); } + + // result retrieval + unique_future<_Result> + get_future() + { + try + { + return _M_promise.get_future(); + } + catch (const future_error& __e) + { + if (__e.code() == future_errc::future_already_retrieved) + throw std::bad_function_call(); + throw; + } + } + + // execution + void + operator()(_ArgTypes... __args) + { + if (!static_cast(_M_task) || _M_promise._M_satisfied()) + throw std::bad_function_call(); + try + { + _Run_task<_Result, _ArgTypes...>::_S_run(_M_promise, _M_task, + std::forward<_ArgTypes>(__args)...); + } + catch (...) + { + _M_promise.set_exception(current_exception()); + } + } + + void reset() { promise<_Result>().swap(_M_promise); } + + private: + function<_Result(_ArgTypes...)> _M_task; + promise<_Result> _M_promise; + }; + + // @} group futures +} + +#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 + // && _GLIBCXX_ATOMIC_BUILTINS_4 + +#endif // __GXX_EXPERIMENTAL_CXX0X__ + +#endif // _GLIBCXX_FUTURE diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am index d218ceaa9ca..4295d4dda66 100644 --- a/libstdc++-v3/src/Makefile.am +++ b/libstdc++-v3/src/Makefile.am @@ -189,6 +189,7 @@ sources = \ condition_variable.cc \ chrono.cc \ thread.cc \ + future.cc \ ${host_sources} \ ${host_sources_extra} @@ -297,6 +298,11 @@ thread.lo: thread.cc thread.o: thread.cc $(CXXCOMPILE) -std=gnu++0x -c $< +future.lo: future.cc + $(LTCXXCOMPILE) -std=gnu++0x -c $< +future.o: future.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. diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in index 9ee5275198b..9134f0472d2 100644 --- a/libstdc++-v3/src/Makefile.in +++ b/libstdc++-v3/src/Makefile.in @@ -87,10 +87,11 @@ 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 \ - 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 + thread.cc future.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 am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \ ctype_members.lo messages_members.lo monetary_members.lo \ numeric_members.lo time_members.lo @@ -113,7 +114,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 \ - thread.lo $(am__objects_1) $(am__objects_4) + thread.lo future.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) @@ -441,6 +442,7 @@ sources = \ condition_variable.cc \ chrono.cc \ thread.cc \ + future.cc \ ${host_sources} \ ${host_sources_extra} @@ -908,6 +910,11 @@ thread.lo: thread.cc thread.o: thread.cc $(CXXCOMPILE) -std=gnu++0x -c $< +future.lo: future.cc + $(LTCXXCOMPILE) -std=gnu++0x -c $< +future.o: future.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 diff --git a/libstdc++-v3/src/future.cc b/libstdc++-v3/src/future.cc new file mode 100644 index 00000000000..ab9d5dbcc69 --- /dev/null +++ b/libstdc++-v3/src/future.cc @@ -0,0 +1,73 @@ +// future -*- C++ -*- + +// Copyright (C) 2009 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +#include + +#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \ + && defined(_GLIBCXX_ATOMIC_BUILTINS_4) +namespace +{ + struct future_error_category : public std::error_category + { + virtual const char* + name() const + { return "future"; } + + virtual std::string message(int __ec) const + { + std::string __msg; + switch (std::future_errc(__ec)) + { + case std::future_errc::broken_promise: + __msg = "Broken promise"; + break; + case std::future_errc::future_already_retrieved: + __msg = "Future already retrieved"; + break; + case std::future_errc::promise_already_satisfied: + __msg = "Promise already satisfied"; + break; + default: + __msg = "Unknown error"; + break; + } + return __msg; + } + }; + + const future_error_category& + __future_category_instance() + { + static const future_error_category __fec; + return __fec; + } +} + +namespace std +{ + const error_category* const future_category = &__future_category_instance(); +} + +#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 + // && _GLIBCXX_ATOMIC_BUILTINS_4 diff --git a/libstdc++-v3/testsuite/30_threads/headers/future/std_c++0x_neg.cc b/libstdc++-v3/testsuite/30_threads/headers/future/std_c++0x_neg.cc new file mode 100644 index 00000000000..5f021b8e5ac --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/headers/future/std_c++0x_neg.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + +#include // { dg-excess-errors "In file included from" } + +// { dg-error "upcoming ISO" "" { target *-*-* } 31 } + + + diff --git a/libstdc++-v3/testsuite/30_threads/headers/future/types_std_c++0x.cc b/libstdc++-v3/testsuite/30_threads/headers/future/types_std_c++0x.cc new file mode 100644 index 00000000000..16a54b4147a --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/headers/future/types_std_c++0x.cc @@ -0,0 +1,49 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + +#include + +void test01() +{ + typedef std::future_errc errc_t; + + using std::future_category; + + typedef std::future_error error_t; + + typedef std::unique_future uniq_t; + typedef std::unique_future uniqr_t; + typedef std::unique_future uniqv_t; + + typedef std::shared_future shar_t; + typedef std::shared_future sharr_t; + typedef std::shared_future sharv_t; + + typedef std::promise promise_t; + typedef std::promise promiser_t; + typedef std::promise promisev_t; + + typedef std::packaged_task ptask_t; + typedef std::packaged_task ptaskr_t; + typedef std::packaged_task ptaskv_t; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/1.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/1.cc new file mode 100644 index 00000000000..a2414333e22 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/1.cc @@ -0,0 +1,53 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::packaged_task; + using namespace __gnu_test; + + packaged_task p1; + VERIFY( !static_cast(p1) ); + packaged_task p2; + VERIFY( !static_cast(p2) ); + packaged_task p3; + VERIFY( !static_cast(p3) ); + packaged_task p4; + VERIFY( !static_cast(p4) ); + packaged_task p5; + VERIFY( !static_cast(p5) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/2.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/2.cc new file mode 100644 index 00000000000..98f5de73c4d --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/2.cc @@ -0,0 +1,64 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +using namespace __gnu_test; + +int f1() { return 0; } +int& f2() { static int i; return i; } +void f3() { } +ClassType f4() { return ClassType(); } + +struct Derived : AbstractClass { + void rotate(int) { } + Derived& operator()(int i) { rotate(i); return *this; } +} f5; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::packaged_task; + + packaged_task p1(f1); + VERIFY( static_cast(p1) ); + packaged_task p2(f2); + VERIFY( static_cast(p2) ); + packaged_task p3(f3); + VERIFY( static_cast(p3) ); + packaged_task p4(f4); + VERIFY( static_cast(p4) ); + packaged_task p5(f5); + VERIFY( static_cast(p5) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc new file mode 100644 index 00000000000..5f02dea0156 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +void test01() +{ + // assign + std::packaged_task p1; + std::packaged_task p2; + p1 = p2; +} + +// { dg-error "used here" "" { target *-*-* } 32 } +// { dg-error "deleted function" "" { target *-*-* } 856 } diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc new file mode 100644 index 00000000000..6a50d7802aa --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +void test01() +{ + // copy + std::packaged_task p1; + std::packaged_task p2(p1); +} + +// { dg-error "used here" "" { target *-*-* } 31 } +// { dg-error "deleted function" "" { target *-*-* } 855 } diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move.cc new file mode 100644 index 00000000000..5335db39949 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move.cc @@ -0,0 +1,49 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int f1() { return 0; } + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + // move + packaged_task p1(f1); + packaged_task p2(std::move(p1)); + VERIFY( !static_cast(p1) ); + VERIFY( static_cast(p2) ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move_assign.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move_assign.cc new file mode 100644 index 00000000000..c23e5e3b72b --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move_assign.cc @@ -0,0 +1,49 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int gen() { return 0; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + // move assign + std::packaged_task p1; + std::packaged_task p2(gen); + p1 = std::move(p2); + VERIFY( static_cast(p1) ); + VERIFY( !static_cast(p2) ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/boolconv.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/boolconv.cc new file mode 100644 index 00000000000..c332b85741d --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/boolconv.cc @@ -0,0 +1,47 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int zero() { return 0; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::packaged_task p1; + VERIFY( !static_cast(p1) ); + + std::packaged_task p2(zero); + VERIFY( static_cast(p2) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future.cc new file mode 100644 index 00000000000..c1bc129e26f --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future.cc @@ -0,0 +1,55 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int& inc(int& i) { return ++i; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::packaged_task p1(inc); + std::unique_future f1 = p1.get_future(); + + VERIFY( !f1.is_ready() ); + + int i1 = 0; + + p1(i1); + + int& i2 = f1.get(); + + VERIFY( &i1 == &i2 ); + VERIFY( i1 == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future2.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future2.cc new file mode 100644 index 00000000000..a6c9c61e5c8 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future2.cc @@ -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 "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +int& inc(int& i) { return ++i; } + +void test01() +{ + bool test = false; + + std::packaged_task p1(inc); + p1.get_future(); + + try + { + p1.get_future(); + VERIFY( false ); + } + catch (std::bad_function_call&) + { + test = true; + } + + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke.cc new file mode 100644 index 00000000000..2797b0606bd --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke.cc @@ -0,0 +1,49 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int zero() { return 0; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::packaged_task p1(zero); + std::unique_future f1 = p1.get_future(); + + p1(); + + VERIFY( static_cast(p1) ); + VERIFY( f1.has_value() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke2.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke2.cc new file mode 100644 index 00000000000..fae15dcac65 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke2.cc @@ -0,0 +1,56 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +bool odd(unsigned i) { return i%2; } + +void test01() +{ + bool test = false; + + std::packaged_task p1(odd); + + p1(5); + + try + { + p1(4); + } + catch (std::bad_function_call&) + { + test = true; + } + + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke3.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke3.cc new file mode 100644 index 00000000000..91d43413d35 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke3.cc @@ -0,0 +1,60 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int& inc(int& i) { ++i; return i; } + +void test01() +{ + bool test = false; + + std::packaged_task p1(inc); + + int i1 = 0; + p1(i1); + + VERIFY( i1 == 1 ); + + try + { + p1(i1); + } + catch (std::bad_function_call&) + { + test = true; + } + + VERIFY( i1 == 1 ); + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke4.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke4.cc new file mode 100644 index 00000000000..eefb313b7a4 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke4.cc @@ -0,0 +1,48 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void thrower() { throw 0; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::packaged_task p1(thrower); + std::unique_future f1 = p1.get_future(); + + p1(); + + VERIFY( f1.has_exception() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke5.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke5.cc new file mode 100644 index 00000000000..925dc108fe9 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke5.cc @@ -0,0 +1,51 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +void noop() { } +void waiter(std::shared_future f) { f.wait(); } + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::packaged_task p1(noop); + std::shared_future f1(p1.get_future()); + std::thread t1(waiter, f1); + + p1(); + + t1.join(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset.cc new file mode 100644 index 00000000000..66b9f3da669 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset.cc @@ -0,0 +1,65 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +int zero() { return 0; } + +void test01() +{ + bool test = false; + using namespace std; + + packaged_task p1(zero); + unique_future f1 = p1.get_future(); + + p1.reset(); + VERIFY( static_cast(p1) ); + + unique_future f2 = p1.get_future(); + VERIFY( !f2.is_ready() ); + + VERIFY( f1.has_exception() ); + try + { + f1.get(); + } + catch (future_error& e) + { + VERIFY( e.code() == make_error_code(future_errc::broken_promise) ); + test = true; + } + + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset2.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset2.cc new file mode 100644 index 00000000000..69ee9a99213 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset2.cc @@ -0,0 +1,53 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int zero() { return 0; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::packaged_task p1(zero); + std::unique_future f1 = p1.get_future(); + + p1(); + p1.reset(); + + VERIFY( static_cast(p1) ); + VERIFY( f1.has_value() ); + + std::unique_future f2 = p1.get_future(); + VERIFY( !f2.is_ready() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/swap.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/swap.cc new file mode 100644 index 00000000000..ced2a00529a --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/swap.cc @@ -0,0 +1,49 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int zero() { return 0; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::packaged_task p1(zero); + std::packaged_task p2; + VERIFY( static_cast(p1) ); + VERIFY( !static_cast(p2) ); + p1.swap(p2); + VERIFY( !static_cast(p1) ); + VERIFY( static_cast(p2) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/requirements/explicit_instantiation.cc new file mode 100644 index 00000000000..4d55603c83e --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/requirements/explicit_instantiation.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +using namespace __gnu_test; +using std::packaged_task; +template class packaged_task; +template class packaged_task; +template class packaged_task; +template class packaged_task; +template class packaged_task; diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc new file mode 100644 index 00000000000..79120b7cd2b --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc @@ -0,0 +1,46 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + using std::promise; + using namespace __gnu_test; + + promise p1; + promise p2; + promise p3; + promise p4; + promise p5; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc new file mode 100644 index 00000000000..0c77173d0bd --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +void test01() +{ + // assign + std::promise p1; + std::promise p2; + p1 = p2; +} + +// { dg-error "used here" "" { target *-*-* } 32 } +// { dg-error "deleted function" "" { target *-*-* } 583 } diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc new file mode 100644 index 00000000000..867c4be3133 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +void test01() +{ + // copy + std::promise p1; + std::promise p2(p1); +} + +// { dg-error "used here" "" { target *-*-* } 31 } +// { dg-error "deleted function" "" { target *-*-* } 567 } diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc new file mode 100644 index 00000000000..8b1e1399801 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc @@ -0,0 +1,55 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + // move assign + promise p1; + p1.set_value(3); + promise p2(std::move(p1)); + VERIFY( p2.get_future().get() == 3 ); + try + { + p1.get_future(); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved)); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc new file mode 100644 index 00000000000..c5bda4d3560 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc @@ -0,0 +1,56 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + // move assign + promise p1; + p1.set_value(3); + promise p2; + p2 = move(p1); + VERIFY( p2.get_future().get() == 3 ); + try + { + p1.get_future(); + VERIFY( false ); + } + catch (future_error& e) + { + VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved)); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc b/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc new file mode 100644 index 00000000000..7e969908a99 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc @@ -0,0 +1,52 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + VERIFY( !f1.is_ready() ); + + int i1 = 0; + + p1.set_value(i1); + + int& i2 = f1.get(); + + VERIFY( &i1 == &i2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc new file mode 100644 index 00000000000..cc44fc47919 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc @@ -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 "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +void test01() +{ + bool test = false; + using namespace std; + + promise p1; + p1.get_future(); + + try + { + p1.get_future(); + VERIFY( false ); + } + catch (future_error& e) + { + VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved)); + test = true; + } + + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc new file mode 100644 index 00000000000..e5b8f60aa3a --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc @@ -0,0 +1,49 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + VERIFY( !f1.is_ready() ); + + p1.set_exception(std::copy_exception(0)); + + VERIFY( f1.has_exception() ); + VERIFY( !f1.has_value() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc new file mode 100644 index 00000000000..3bbe28d48da --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc @@ -0,0 +1,95 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test = false; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + p1.set_exception(std::copy_exception(0)); + + try + { + p1.set_exception(std::copy_exception(1)); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + try + { + f1.get(); + test = false; + } + catch(int i) + { + VERIFY( i == 0 ); + } + + VERIFY( test ); +} + +void test02() +{ + bool test = false; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + p1.set_value(2); + + try + { + p1.set_exception(std::copy_exception(0)); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + VERIFY( f1.has_value() ); + VERIFY( !f1.has_exception() ); + VERIFY( test ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc new file mode 100644 index 00000000000..978ef1914b0 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc @@ -0,0 +1,105 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + VERIFY( !f1.is_ready() ); + + p1.set_value(0); + + int&& i1 = f1.get(); + + VERIFY( i1 == 0 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + VERIFY( !f1.is_ready() ); + + p1.set_value(rvalstruct(1)); + + rvalstruct r1(f1.get()); + + VERIFY( r1.valid ); + VERIFY( r1.val == 1 ); +} + + +void test03() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + VERIFY( !f1.is_ready() ); + + int i1 = 0; + p1.set_value(i1); + int& i2 = f1.get(); + + VERIFY( &i1 == &i2 ); +} + +void test04() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + VERIFY( !f1.is_ready() ); + + p1.set_value(); + f1.get(); + + VERIFY( f1.is_ready() ); +} + +int main() +{ + test01(); + test02(); + test03(); + test04(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc new file mode 100644 index 00000000000..58e2fe813e4 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc @@ -0,0 +1,88 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test = false; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + p1.set_value(1); + + try + { + p1.set_value(2); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + VERIFY( f1.has_value() ); + VERIFY( f1.get() == 1 ); + VERIFY( test ); +} + +void test02() +{ + bool test = false; + + std::promise p1; + std::unique_future f1 = p1.get_future(); + + p1.set_value(3); + + try + { + p1.set_exception(std::copy_exception(4)); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + VERIFY( f1.has_value() ); + VERIFY( !f1.has_exception() ); + VERIFY( f1.get() == 3 ); + VERIFY( test ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc new file mode 100644 index 00000000000..92581964e3c --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc @@ -0,0 +1,87 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + + +// Test promise::set_value() for deadlock by checking if the state is ready +// during construction and destruction of the associated state. + +struct tester +{ + tester(int); + tester(const tester&); + tester() = delete; + ~tester(); + tester& operator=(const tester&); +}; + +std::promise pglobal; +std::unique_future fglobal = pglobal.get_future(); + +tester::tester(int) +{ + bool test __attribute__((unused)) = true; + VERIFY (!fglobal.is_ready()); +} + +tester::tester(const tester&) +{ + bool test __attribute__((unused)) = true; + // if this copy happens while a mutex is locked next line could deadlock: + VERIFY (!fglobal.is_ready()); +} + +tester& tester::operator=(const tester&) +{ + bool test __attribute__((unused)) = true; + // if this copy happens while a mutex is locked next line could deadlock: + VERIFY (!fglobal.is_ready()); + return *this; +} + +tester::~tester() +{ + bool test __attribute__((unused)) = true; + VERIFY (fglobal.is_ready()); +} + +void test01() +{ + bool test __attribute__((unused)) = true; + + pglobal.set_value( tester(1) ); + + VERIFY( fglobal.is_ready() ); +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc b/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc new file mode 100644 index 00000000000..8bfbdfd6c8f --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc @@ -0,0 +1,46 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::promise p2; + p1.set_value(1); + p1.swap(p2); + VERIFY( !p1.get_future().is_ready() ); + VERIFY( p2.get_future().is_ready() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc new file mode 100644 index 00000000000..903b3ab146e --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +using namespace __gnu_test; +using std::promise; +template class promise; +template class promise; +template class promise; +template class promise; +template class promise; diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc new file mode 100644 index 00000000000..7e3c96ffc1e --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc @@ -0,0 +1,38 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +extern std::shared_future& get(); + +void test01() +{ + // assign + std::shared_future& p1 = get(); + std::shared_future& p2 = get(); + p1 = p2; +} + +// { dg-error "used here" "" { target *-*-* } 34 } +// { dg-error "deleted function" "" { target *-*-* } 474 } diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/copy.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/copy.cc new file mode 100644 index 00000000000..16954a1d4c1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/copy.cc @@ -0,0 +1,42 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +extern std::unique_future& get(); + +void test01() +{ + using std::shared_future; + + shared_future p1 = get(); + shared_future p2(p1); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/default_neg.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/default_neg.cc new file mode 100644 index 00000000000..cc4aadfce6f --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/default_neg.cc @@ -0,0 +1,45 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + using std::shared_future; + using namespace __gnu_test; + + shared_future p1; // { dg-error "22: error: no match" } + shared_future p2; // { dg-error "23: error: no match" } + shared_future p3; // { dg-error "23: error: no match" } + shared_future p4; // { dg-error "28: error: no match" } + shared_future p5; // { dg-error "33: error: no match" } +} + +int main() +{ + test01(); + return 0; +} +// { dg-excess-errors "note" } diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/move.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/move.cc new file mode 100644 index 00000000000..3494a10463f --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/move.cc @@ -0,0 +1,41 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +void test01() +{ + // construct from rvalue unique_future + std::promise p1; + std::unique_future f1(p1.get_future()); + std::shared_future f2(std::move(f1)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/get.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/get.cc new file mode 100644 index 00000000000..bf773c31d52 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/get.cc @@ -0,0 +1,78 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int value = 99; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + p1.set_value(value); + VERIFY( f1.get() == value ); + VERIFY( f2.get() == value ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + p1.set_value(value); + VERIFY( &f1.get() == &value ); + VERIFY( &f2.get() == &value ); +} + +void test03() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + p1.set_value(); + f1.get(); + f2.get(); +} + +int main() +{ + test01(); + test02(); + test03(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/get2.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/get2.cc new file mode 100644 index 00000000000..80dd368a973 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/get2.cc @@ -0,0 +1,127 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +int value = 99; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + p1.set_exception(std::copy_exception(value)); + try + { + (void) f1.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } + try + { + (void) f2.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + p1.set_exception(std::copy_exception(value)); + try + { + (void) f1.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } + try + { + (void) f2.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } +} + +void test03() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + p1.set_exception(std::copy_exception(value)); + try + { + f1.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } + try + { + f2.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } +} + +int main() +{ + test01(); + test02(); + test03(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc new file mode 100644 index 00000000000..97d398025e5 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc @@ -0,0 +1,70 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + VERIFY( !f1.has_exception() ); + VERIFY( !f2.has_exception() ); + + p1.set_exception(std::copy_exception(1)); + + VERIFY( f1.has_exception() ); + VERIFY( f2.has_exception() ); +} + +void test02() +{ + std::promise p1; + bool test __attribute__((unused)) = true; + + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + VERIFY( !f1.has_exception() ); + VERIFY( !f2.has_exception() ); + + p1.set_value(1); + + VERIFY( !f1.has_exception() ); + VERIFY( !f2.has_exception() ); +} + +int main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc new file mode 100644 index 00000000000..8903c825f88 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc @@ -0,0 +1,70 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + VERIFY( !f1.has_value() ); + VERIFY( !f2.has_value() ); + + p1.set_value(1); + + VERIFY( f1.has_value() ); + VERIFY( f2.has_value() ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + VERIFY( !f1.has_value() ); + VERIFY( !f2.has_value() ); + + p1.set_exception(std::copy_exception(1)); + + VERIFY( !f1.has_value() ); + VERIFY( !f2.has_value() ); +} + +int main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/is_ready.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/is_ready.cc new file mode 100644 index 00000000000..eb2252a664b --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/is_ready.cc @@ -0,0 +1,51 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + VERIFY( !f1.is_ready() ); + VERIFY( !f2.is_ready() ); + + p1.set_value(1); + + VERIFY( f1.is_ready() ); + VERIFY( f2.is_ready() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/wait.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait.cc new file mode 100644 index 00000000000..a4e325b0d96 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait.cc @@ -0,0 +1,56 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include +#include + +void wait(std::shared_future f) +{ + f.wait(); +} + +void test01() +{ + std::promise p1; + std::shared_future f1(p1.get_future()); + + std::thread t1(wait, f1); + std::thread t2(wait, f1); + std::thread t3(wait, f1); + + p1.set_value(); + t1.join(); + t2.join(); + t3.join(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_for.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_for.cc new file mode 100644 index 00000000000..408b6460225 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_for.cc @@ -0,0 +1,56 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + std::chrono::milliseconds delay(100); + + VERIFY( !f1.wait_for(delay) ); + VERIFY( !f2.wait_for(delay) ); + + p1.set_value(1); + + auto before = std::chrono::system_clock::now(); + VERIFY( f1.wait_for(delay) ); + VERIFY( f2.wait_for(delay) ); + VERIFY( std::chrono::system_clock::now() < (before + 2*delay) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_until.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_until.cc new file mode 100644 index 00000000000..561fb20952d --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_until.cc @@ -0,0 +1,64 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +std::chrono::system_clock::time_point make_time(int i) +{ + return std::chrono::system_clock::now() + std::chrono::milliseconds(i); +} + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::shared_future f1(p1.get_future()); + std::shared_future f2(f1); + + auto when = make_time(10); + VERIFY( !f1.wait_until(make_time(10)) ); + VERIFY( std::chrono::system_clock::now() >= when ); + + when = make_time(10); + VERIFY( !f2.wait_until(make_time(10)) ); + VERIFY( std::chrono::system_clock::now() >= when ); + + p1.set_value(1); + + when = make_time(100); + VERIFY( f1.wait_until(when) ); + VERIFY( f2.wait_until(when) ); + VERIFY( std::chrono::system_clock::now() < when ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/30_threads/shared_future/requirements/explicit_instantiation.cc new file mode 100644 index 00000000000..4c1b3b276bd --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/requirements/explicit_instantiation.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +using namespace __gnu_test; +using std::shared_future; +template class shared_future; +template class shared_future; +template class shared_future; +template class shared_future; +template class shared_future; diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc new file mode 100644 index 00000000000..e9525e4da7a --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc @@ -0,0 +1,38 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +extern std::unique_future& get(); + +void test01() +{ + // assign + std::unique_future& p1 = get(); + std::unique_future& p2 = get(); + p1 = p2; +} + +// { dg-error "used here" "" { target *-*-* } 34 } +// { dg-error "deleted function" "" { target *-*-* } 394 } diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc new file mode 100644 index 00000000000..bf40e054af0 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +extern std::unique_future& get(); + +void test01() +{ + // copy + std::unique_future& p1 = get(); + std::unique_future p2(p1); +} + +// { dg-error "used here" "" { target *-*-* } 33 } +// { dg-error "deleted function" "" { target *-*-* } 393 } diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/default_neg.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/default_neg.cc new file mode 100644 index 00000000000..ba5066bfcab --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/default_neg.cc @@ -0,0 +1,45 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + using std::unique_future; + using namespace __gnu_test; + + unique_future p1; // { dg-error "22: error: no match" } + unique_future p2; // { dg-error "23: error: no match" } + unique_future p3; // { dg-error "23: error: no match" } + unique_future p4; // { dg-error "28: error: no match" } + unique_future p5; // { dg-error "33: error: no match" } +} + +int main() +{ + test01(); + return 0; +} +// { dg-excess-errors "note" } diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/move.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/move.cc new file mode 100644 index 00000000000..17eaa914e4e --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/move.cc @@ -0,0 +1,41 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include + +void test01() +{ + // move + std::promise p1; + std::unique_future f1(p1.get_future()); + std::unique_future f2(std::move(f1)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/get.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/get.cc new file mode 100644 index 00000000000..5c9a4548491 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/get.cc @@ -0,0 +1,70 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +int value = 99; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + p1.set_value(value); + VERIFY( f1.get() == value ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + p1.set_value(value); + VERIFY( &f1.get() == &value ); +} + +void test03() +{ + std::promise p1; + std::unique_future f1(p1.get_future()); + + p1.set_value(); + f1.get(); +} + +int main() +{ + test01(); + test02(); + test03(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/get2.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/get2.cc new file mode 100644 index 00000000000..e6317fed838 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/get2.cc @@ -0,0 +1,97 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +int value = 99; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + p1.set_exception(std::copy_exception(value)); + try + { + (void) f1.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + p1.set_exception(std::copy_exception(value)); + try + { + (void) f1.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } +} + +void test03() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + p1.set_exception(std::copy_exception(value)); + try + { + f1.get(); + VERIFY( false ); + } + catch (int& e) + { + VERIFY( e == value ); + } +} + +int main() +{ + test01(); + test02(); + test03(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/has_exception.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/has_exception.cc new file mode 100644 index 00000000000..1d5baf88393 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/has_exception.cc @@ -0,0 +1,64 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + VERIFY( !f1.has_exception() ); + + p1.set_exception(std::copy_exception(1)); + + VERIFY( f1.has_exception() ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + VERIFY( !f1.has_exception() ); + + p1.set_value(1); + + VERIFY( !f1.has_exception() ); +} + +int main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/has_value.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/has_value.cc new file mode 100644 index 00000000000..f1f96f21ddc --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/has_value.cc @@ -0,0 +1,65 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + VERIFY( !f1.has_value() ); + + p1.set_value(1); + + VERIFY( f1.has_value() ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + VERIFY( !f1.has_value() ); + + p1.set_exception(std::copy_exception(1)); + + VERIFY( !f1.has_value() ); +} + +int main() +{ + test01(); + test02(); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/is_ready.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/is_ready.cc new file mode 100644 index 00000000000..6f2b6885595 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/is_ready.cc @@ -0,0 +1,48 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + VERIFY( !f1.is_ready() ); + + p1.set_value(1); + + VERIFY( f1.is_ready() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/wait.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait.cc new file mode 100644 index 00000000000..b9c9402cf31 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait.cc @@ -0,0 +1,54 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include +#include +#include + + +void wait(std::unique_future& f) +{ + f.wait(); +} + +void test01() +{ + std::promise p1; + std::unique_future f1(p1.get_future()); + + std::thread t1(wait, std::ref(f1)); + + p1.set_value(); + t1.join(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_for.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_for.cc new file mode 100644 index 00000000000..065240097b1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_for.cc @@ -0,0 +1,53 @@ +// { 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-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + std::chrono::milliseconds delay(100); + + VERIFY( !f1.wait_for(delay) ); + + p1.set_value(1); + + auto before = std::chrono::system_clock::now(); + VERIFY( f1.wait_for(delay) ); + VERIFY( std::chrono::system_clock::now() < (before + delay) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_until.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_until.cc new file mode 100644 index 00000000000..55bdcbcc76c --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_until.cc @@ -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 "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +std::chrono::system_clock::time_point make_time(int i) +{ + return std::chrono::system_clock::now() + std::chrono::milliseconds(i); +} + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p1; + std::unique_future f1(p1.get_future()); + + auto when = make_time(10); + VERIFY( !f1.wait_until(when) ); + VERIFY( std::chrono::system_clock::now() >= when ); + + p1.set_value(1); + + when = make_time(100); + VERIFY( f1.wait_until(when) ); + VERIFY( std::chrono::system_clock::now() < when ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/30_threads/unique_future/requirements/explicit_instantiation.cc new file mode 100644 index 00000000000..01e5c5924b2 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_future/requirements/explicit_instantiation.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include + +using namespace __gnu_test; +using std::unique_future; +template class unique_future; +template class unique_future; +template class unique_future; +template class unique_future; +template class unique_future; diff --git a/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc b/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc new file mode 100644 index 00000000000..21405e18ad4 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// . + + +#include +#include +#include + +void poll(std::shared_future f) +{ + while (!f.is_ready()) + { } +} + +int main() +{ + using namespace __gnu_test; + time_counter time; + resource_counter resource; + + const int n = 20; + std::promise p; + std::shared_future f = p.get_future(); + std::thread pollers[n]; + for (int i=0; i < n; ++i) + pollers[i] = std::thread(poll, f); + + start_counters(time, resource); + + for (int i = 0; i < 1000000; ++i) + (void)f.is_ready(); + p.set_value(); + + for (int i=0; i < n; ++i) + pollers[i].join(); + + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +}