future: New.

2009-06-21  Jonathan Wakely  <jwakely.gcc@gmail.com>

	* 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
This commit is contained in:
Jonathan Wakely 2009-06-21 14:02:09 +00:00 committed by Jonathan Wakely
parent f3b57ab079
commit c910ceff6a
69 changed files with 4453 additions and 5 deletions

View file

@ -1,3 +1,78 @@
2009-06-21 Jonathan Wakely <jwakely.gcc@gmail.com>
* 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 <paolo.carlini@oracle.com>
* Revert last Change.

View file

@ -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.

View file

@ -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 \

View file

@ -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 \

View file

@ -0,0 +1,925 @@
// <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
// <http://www.gnu.org/licenses/>.
/** @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 <c++0x_warning.h>
#else
#include <functional>
#include <memory>
#include <mutex>
#include <condition_variable>
#include <system_error>
#include <exception>
#include <cstdatomic>
#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<future_errc> { }
template<>
struct is_error_code_enum<future_errc> : 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<int>(__errc), *future_category); }
// TODO: requires constexpr
inline error_condition make_error_condition(future_errc __errc)
{ return error_condition(static_cast<int>(__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<typename _Res>
using _Future_ptr = unique_ptr<_Res, _Future_result_base::_Deleter>;
*/
template<typename _Res>
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<mutex> __lock(_M_mutex);
if (!_M_ready())
_M_cond.wait(__lock, std::bind(&_Future_state::_M_ready, this));
return *_M_result;
}
template<typename _Rep, typename _Period>
bool
wait_for(const chrono::duration<_Rep, _Period>& __rel)
{
unique_lock<mutex> __lock(_M_mutex);
return _M_ready() || _M_cond.wait_for(__lock, __rel,
std::bind(&_Future_state::_M_ready, this));
}
template<typename _Clock, typename _Duration>
bool
wait_until(const chrono::time_point<_Clock, _Duration>& __abs)
{
unique_lock<mutex> __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<mutex> __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<bool>(__res))
{
__res->_M_error
= std::copy_exception(future_error(future_errc::broken_promise));
{
lock_guard<mutex> __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<mutex> __lock(_M_mutex);
return _M_result.get();
}
bool _M_ready() const { return static_cast<bool>(_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<typename _Result, bool = is_scalar<_Result>::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<typename _Result>
struct _Move_future_result<_Result, true>
{
typedef _Result __rval_type;
static _Result _S_move(_Result __res) { return __res; }
};
template<typename _Result>
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<void*>(&_M_storage); }
typename aligned_storage<sizeof(_Result),
alignment_of<_Result>::value>::type _M_storage;
bool _M_initialized;
};
template<typename _Result>
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<void> : _Future_result_base
{
void _M_destroy() { delete this; }
};
/// unique_future
template<typename _Result>
class unique_future;
/// shared_future
template<typename _Result>
class shared_future;
// common implementation for unique_future and shared_future
template<typename _Result>
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<typename _Rep, typename _Period>
bool
wait_for(const chrono::duration<_Rep, _Period>& __rel) const
{ return this->_M_state->wait_for(__rel); }
template<typename _Clock, typename _Duration>
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<bool>(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<typename _Result>
class promise;
// primary template for unique_future
template<typename _Result>
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<R&>
template<typename _Result>
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<void>
template<>
class unique_future<void> : public _Future_impl<void>
{
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<void> _Base_type;
typedef _Base_type::_State_ptr _State_ptr;
friend class promise<void>;
explicit
unique_future(const _State_ptr& __state) : _Base_type(__state) { }
};
// primary template for unique_future
template<typename _Result>
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<R&>
template<typename _Result>
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<void>
template<>
class shared_future<void> : public _Future_impl<void>
{
public:
/// Copy constructor
shared_future(const shared_future& __sf) : _Base_type(__sf) { }
/// Construct from a unique_future rvalue
shared_future(unique_future<void>&& __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<void> _Base_type;
};
// now we can define the protected _Future_impl constructors
template<typename _Result>
_Future_impl<_Result>::_Future_impl(const shared_future<_Result>& __sf)
: _M_state(__sf._M_state)
{ }
template<typename _Result>
_Future_impl<_Result>::_Future_impl(unique_future<_Result>&& __uf)
: _M_state(std::move(__uf._M_state))
{ }
template<typename> class packaged_task; // undefined
// primary template for promise
template<typename _Result>
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<typename _Allocator>
promise(allocator_arg_t, const _Allocator& __a);
template<typename _Allocator>
promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
*/
promise(const promise&) = delete;
~promise()
{
if (static_cast<bool>(_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<typename> friend class packaged_task;
typedef _Move_future_result<_Result> _Mover;
bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
shared_ptr<_Future_state> _M_future;
typename _Future_ptr<_Future_result<_Result>>::type _M_storage;
};
// partial specialization for promise<R&>
template<typename _Result>
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<typename _Allocator>
promise(allocator_arg_t, const _Allocator& __a);
template<typename _Allocator>
promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
*/
promise(const promise&) = delete;
~promise()
{
if (static_cast<bool>(_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<typename> friend class packaged_task;
bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
shared_ptr<_Future_state> _M_future;
typename _Future_ptr<_Future_result<_Result&>>::type _M_storage;
};
// specialization for promise<void>
template<>
class promise<void>
{
public:
promise()
: _M_future(std::make_shared<_Future_state>()),
_M_storage(new _Future_result<void>())
{ }
promise(promise&& __rhs)
: _M_future(std::move(__rhs._M_future)),
_M_storage(std::move(__rhs._M_storage))
{ }
// TODO: requires allocator concepts
/*
template<typename _Allocator>
promise(allocator_arg_t, const _Allocator& __a);
template<typename _Allocator>
promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
*/
promise(const promise&) = delete;
~promise()
{
if (static_cast<bool>(_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<void>
get_future()
{ return unique_future<void>(_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<typename> friend class packaged_task;
bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
shared_ptr<_Future_state> _M_future;
_Future_ptr<_Future_result<void>>::type _M_storage;
};
// TODO: requires allocator concepts
/*
template<typename _Result, class Alloc>
concept_map UsesAllocator<promise<_Result>, Alloc>
{
typedef Alloc allocator_type;
}
*/
template<typename _Result, typename... _ArgTypes>
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<void(...)>
template<typename... _ArgTypes>
struct _Run_task<void, _ArgTypes...>
{
static void
_S_run(promise<void>& __p, function<void(_ArgTypes...)>& __f,
_ArgTypes... __args)
{
__f(std::forward<_ArgTypes>(__args)...);
__p.set_value();
}
};
template<typename _Result, typename... _ArgTypes>
class packaged_task<_Result(_ArgTypes...)>
{
public:
typedef _Result result_type;
// construction and destruction
packaged_task() { }
template<typename _Fn>
explicit
packaged_task(const _Fn& __fn) : _M_task(__fn) { }
template<typename _Fn>
explicit
packaged_task(_Fn&& __fn) : _M_task(std::move(__fn)) { }
explicit
packaged_task(_Result(*__fn)(_ArgTypes...)) : _M_task(__fn) { }
// TODO: requires allocator concepts
/*
template<typename _Fn, typename _Allocator>
explicit
packaged_task(allocator_arg_t __tag, const _Allocator& __a, _Fn __fn)
: _M_task(__tag, __a, __fn), _M_promise(__tag, __a)
{ }
template<typename _Fn, typename _Allocator>
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<bool>(_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<bool>(_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

View file

@ -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.

View file

@ -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

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#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

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future> // { dg-excess-errors "In file included from" }
// { dg-error "upcoming ISO" "" { target *-*-* } 31 }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
void test01()
{
typedef std::future_errc errc_t;
using std::future_category;
typedef std::future_error error_t;
typedef std::unique_future<int> uniq_t;
typedef std::unique_future<int&> uniqr_t;
typedef std::unique_future<void> uniqv_t;
typedef std::shared_future<int> shar_t;
typedef std::shared_future<int&> sharr_t;
typedef std::shared_future<void> sharv_t;
typedef std::promise<int> promise_t;
typedef std::promise<int&> promiser_t;
typedef std::promise<void> promisev_t;
typedef std::packaged_task<int> ptask_t;
typedef std::packaged_task<int&> ptaskr_t;
typedef std::packaged_task<void> ptaskv_t;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
#include <testsuite_tr1.h>
void test01()
{
bool test __attribute__((unused)) = true;
using std::packaged_task;
using namespace __gnu_test;
packaged_task<int ()> p1;
VERIFY( !static_cast<bool>(p1) );
packaged_task<int& ()> p2;
VERIFY( !static_cast<bool>(p2) );
packaged_task<void ()> p3;
VERIFY( !static_cast<bool>(p3) );
packaged_task<ClassType ()> p4;
VERIFY( !static_cast<bool>(p4) );
packaged_task<AbstractClass& (int)> p5;
VERIFY( !static_cast<bool>(p5) );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
#include <testsuite_tr1.h>
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<int ()> p1(f1);
VERIFY( static_cast<bool>(p1) );
packaged_task<int& ()> p2(f2);
VERIFY( static_cast<bool>(p2) );
packaged_task<void ()> p3(f3);
VERIFY( static_cast<bool>(p3) );
packaged_task<ClassType ()> p4(f4);
VERIFY( static_cast<bool>(p4) );
packaged_task<AbstractClass& (int)> p5(f5);
VERIFY( static_cast<bool>(p5) );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
void test01()
{
// assign
std::packaged_task<int()> p1;
std::packaged_task<int()> p2;
p1 = p2;
}
// { dg-error "used here" "" { target *-*-* } 32 }
// { dg-error "deleted function" "" { target *-*-* } 856 }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
void test01()
{
// copy
std::packaged_task<int()> p1;
std::packaged_task<int()> p2(p1);
}
// { dg-error "used here" "" { target *-*-* } 31 }
// { dg-error "deleted function" "" { target *-*-* } 855 }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int f1() { return 0; }
void test01()
{
bool test __attribute__((unused)) = true;
using namespace std;
// move
packaged_task<int()> p1(f1);
packaged_task<int()> p2(std::move(p1));
VERIFY( !static_cast<bool>(p1) );
VERIFY( static_cast<bool>(p2) );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int gen() { return 0; }
void test01()
{
bool test __attribute__((unused)) = true;
// move assign
std::packaged_task<int()> p1;
std::packaged_task<int()> p2(gen);
p1 = std::move(p2);
VERIFY( static_cast<bool>(p1) );
VERIFY( !static_cast<bool>(p2) );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int zero() { return 0; }
void test01()
{
bool test __attribute__((unused)) = true;
std::packaged_task<int()> p1;
VERIFY( !static_cast<bool>(p1) );
std::packaged_task<int()> p2(zero);
VERIFY( static_cast<bool>(p2) );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int& inc(int& i) { return ++i; }
void test01()
{
bool test __attribute__((unused)) = true;
std::packaged_task<int&(int&)> p1(inc);
std::unique_future<int&> 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;
}

View file

@ -0,0 +1,57 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// { 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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <system_error>
#include <testsuite_hooks.h>
int& inc(int& i) { return ++i; }
void test01()
{
bool test = false;
std::packaged_task<int&(int&)> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int zero() { return 0; }
void test01()
{
bool test __attribute__((unused)) = true;
std::packaged_task<int()> p1(zero);
std::unique_future<int> f1 = p1.get_future();
p1();
VERIFY( static_cast<bool>(p1) );
VERIFY( f1.has_value() );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
bool odd(unsigned i) { return i%2; }
void test01()
{
bool test = false;
std::packaged_task<bool(unsigned)> p1(odd);
p1(5);
try
{
p1(4);
}
catch (std::bad_function_call&)
{
test = true;
}
VERIFY( test );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int& inc(int& i) { ++i; return i; }
void test01()
{
bool test = false;
std::packaged_task<void(int&)> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void thrower() { throw 0; }
void test01()
{
bool test __attribute__((unused)) = true;
std::packaged_task<void()> p1(thrower);
std::unique_future<void> f1 = p1.get_future();
p1();
VERIFY( f1.has_exception() );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <thread>
#include <testsuite_hooks.h>
void noop() { }
void waiter(std::shared_future<void> f) { f.wait(); }
void test01()
{
bool test __attribute__((unused)) = true;
std::packaged_task<void()> p1(noop);
std::shared_future<void> f1(p1.get_future());
std::thread t1(waiter, f1);
p1();
t1.join();
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <system_error>
#include <testsuite_hooks.h>
int zero() { return 0; }
void test01()
{
bool test = false;
using namespace std;
packaged_task<int()> p1(zero);
unique_future<int> f1 = p1.get_future();
p1.reset();
VERIFY( static_cast<bool>(p1) );
unique_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int zero() { return 0; }
void test01()
{
bool test __attribute__((unused)) = true;
std::packaged_task<int()> p1(zero);
std::unique_future<int> f1 = p1.get_future();
p1();
p1.reset();
VERIFY( static_cast<bool>(p1) );
VERIFY( f1.has_value() );
std::unique_future<int> f2 = p1.get_future();
VERIFY( !f2.is_ready() );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int zero() { return 0; }
void test01()
{
bool test __attribute__((unused)) = true;
std::packaged_task<int()> p1(zero);
std::packaged_task<int()> p2;
VERIFY( static_cast<bool>(p1) );
VERIFY( !static_cast<bool>(p2) );
p1.swap(p2);
VERIFY( !static_cast<bool>(p1) );
VERIFY( static_cast<bool>(p2) );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_tr1.h>
using namespace __gnu_test;
using std::packaged_task;
template class packaged_task<int()>;
template class packaged_task<int&()>;
template class packaged_task<void()>;
template class packaged_task<ClassType(int)>;
template class packaged_task<AbstractClass&(int)>;

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_tr1.h>
void test01()
{
using std::promise;
using namespace __gnu_test;
promise<int> p1;
promise<int&> p2;
promise<void> p3;
promise<ClassType> p4;
promise<AbstractClass&> p5;
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
void test01()
{
// assign
std::promise<int> p1;
std::promise<int> p2;
p1 = p2;
}
// { dg-error "used here" "" { target *-*-* } 32 }
// { dg-error "deleted function" "" { target *-*-* } 583 }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
void test01()
{
// copy
std::promise<int> p1;
std::promise<int> p2(p1);
}
// { dg-error "used here" "" { target *-*-* } 31 }
// { dg-error "deleted function" "" { target *-*-* } 567 }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
using namespace std;
// move assign
promise<int> p1;
p1.set_value(3);
promise<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
using namespace std;
// move assign
promise<int> p1;
p1.set_value(3);
promise<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int&> p1;
std::unique_future<int&> 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;
}

View file

@ -0,0 +1,57 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// { 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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <system_error>
#include <testsuite_hooks.h>
void test01()
{
bool test = false;
using namespace std;
promise<int&> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::unique_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test = false;
std::promise<int> p1;
std::unique_future<int> 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<int> p1;
std::unique_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
#include <testsuite_rvalref.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::unique_future<int> 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<rvalstruct> p1;
std::unique_future<rvalstruct> 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<int&> p1;
std::unique_future<int&> 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<void> p1;
std::unique_future<void> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test = false;
std::promise<int> p1;
std::unique_future<int> 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<int> p1;
std::unique_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
// 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<tester> pglobal;
std::unique_future<tester> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::promise<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_tr1.h>
using namespace __gnu_test;
using std::promise;
template class promise<int>;
template class promise<int&>;
template class promise<void>;
template class promise<ClassType>;
template class promise<ClassType&>;

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
extern std::shared_future<int>& get();
void test01()
{
// assign
std::shared_future<int>& p1 = get();
std::shared_future<int>& p2 = get();
p1 = p2;
}
// { dg-error "used here" "" { target *-*-* } 34 }
// { dg-error "deleted function" "" { target *-*-* } 474 }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
extern std::unique_future<int>& get();
void test01()
{
using std::shared_future;
shared_future<int> p1 = get();
shared_future<int> p2(p1);
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_tr1.h>
void test01()
{
using std::shared_future;
using namespace __gnu_test;
shared_future<int> p1; // { dg-error "22: error: no match" }
shared_future<int&> p2; // { dg-error "23: error: no match" }
shared_future<void> p3; // { dg-error "23: error: no match" }
shared_future<ClassType> p4; // { dg-error "28: error: no match" }
shared_future<AbstractClass&> p5; // { dg-error "33: error: no match" }
}
int main()
{
test01();
return 0;
}
// { dg-excess-errors "note" }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
void test01()
{
// construct from rvalue unique_future
std::promise<int> p1;
std::unique_future<int> f1(p1.get_future());
std::shared_future<int> f2(std::move(f1));
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int value = 99;
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> f2(f1);
p1.set_value(value);
VERIFY( f1.get() == value );
VERIFY( f2.get() == value );
}
void test02()
{
bool test __attribute__((unused)) = true;
std::promise<int&> p1;
std::shared_future<int&> f1(p1.get_future());
std::shared_future<int&> f2(f1);
p1.set_value(value);
VERIFY( &f1.get() == &value );
VERIFY( &f2.get() == &value );
}
void test03()
{
bool test __attribute__((unused)) = true;
std::promise<void> p1;
std::shared_future<void> f1(p1.get_future());
std::shared_future<void> f2(f1);
p1.set_value();
f1.get();
f2.get();
}
int main()
{
test01();
test02();
test03();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <exception>
#include <testsuite_hooks.h>
int value = 99;
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> 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<int&> p1;
std::shared_future<int&> f1(p1.get_future());
std::shared_future<int&> 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<void> p1;
std::shared_future<void> f1(p1.get_future());
std::shared_future<void> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> 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<int> p1;
bool test __attribute__((unused)) = true;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> 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<int> p1;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <thread>
#include <mutex>
#include <testsuite_hooks.h>
void wait(std::shared_future<void> f)
{
f.wait();
}
void test01()
{
std::promise<void> p1;
std::shared_future<void> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <chrono>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <chrono>
#include <testsuite_hooks.h>
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<int> p1;
std::shared_future<int> f1(p1.get_future());
std::shared_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_tr1.h>
using namespace __gnu_test;
using std::shared_future;
template class shared_future<int>;
template class shared_future<int&>;
template class shared_future<void>;
template class shared_future<ClassType>;
template class shared_future<ClassType&>;

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
extern std::unique_future<int>& get();
void test01()
{
// assign
std::unique_future<int>& p1 = get();
std::unique_future<int>& p2 = get();
p1 = p2;
}
// { dg-error "used here" "" { target *-*-* } 34 }
// { dg-error "deleted function" "" { target *-*-* } 394 }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
extern std::unique_future<int>& get();
void test01()
{
// copy
std::unique_future<int>& p1 = get();
std::unique_future<int> p2(p1);
}
// { dg-error "used here" "" { target *-*-* } 33 }
// { dg-error "deleted function" "" { target *-*-* } 393 }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_tr1.h>
void test01()
{
using std::unique_future;
using namespace __gnu_test;
unique_future<int> p1; // { dg-error "22: error: no match" }
unique_future<int&> p2; // { dg-error "23: error: no match" }
unique_future<void> p3; // { dg-error "23: error: no match" }
unique_future<ClassType> p4; // { dg-error "28: error: no match" }
unique_future<AbstractClass&> p5; // { dg-error "33: error: no match" }
}
int main()
{
test01();
return 0;
}
// { dg-excess-errors "note" }

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
void test01()
{
// move
std::promise<int> p1;
std::unique_future<int> f1(p1.get_future());
std::unique_future<int> f2(std::move(f1));
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
int value = 99;
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::unique_future<int> f1(p1.get_future());
p1.set_value(value);
VERIFY( f1.get() == value );
}
void test02()
{
bool test __attribute__((unused)) = true;
std::promise<int&> p1;
std::unique_future<int&> f1(p1.get_future());
p1.set_value(value);
VERIFY( &f1.get() == &value );
}
void test03()
{
std::promise<void> p1;
std::unique_future<void> f1(p1.get_future());
p1.set_value();
f1.get();
}
int main()
{
test01();
test02();
test03();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <exception>
#include <testsuite_hooks.h>
int value = 99;
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::unique_future<int> 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<int&> p1;
std::unique_future<int&> 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<void> p1;
std::unique_future<void> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::unique_future<int> 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<int> p1;
std::unique_future<int> f1(p1.get_future());
VERIFY( !f1.has_exception() );
p1.set_value(1);
VERIFY( !f1.has_exception() );
}
int main()
{
test01();
test02();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::unique_future<int> 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<int> p1;
std::unique_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::unique_future<int> f1(p1.get_future());
VERIFY( !f1.is_ready() );
p1.set_value(1);
VERIFY( f1.is_ready() );
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <chrono>
#include <thread>
#include <mutex>
#include <testsuite_hooks.h>
void wait(std::unique_future<void>& f)
{
f.wait();
}
void test01()
{
std::promise<void> p1;
std::unique_future<void> f1(p1.get_future());
std::thread t1(wait, std::ref(f1));
p1.set_value();
t1.join();
}
int main()
{
test01();
return 0;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <chrono>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::promise<int> p1;
std::unique_future<int> 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;
}

View file

@ -0,0 +1,58 @@
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// { 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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <chrono>
#include <testsuite_hooks.h>
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<int> p1;
std::unique_future<int> 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;
}

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <testsuite_tr1.h>
using namespace __gnu_test;
using std::unique_future;
template class unique_future<int>;
template class unique_future<int&>;
template class unique_future<void>;
template class unique_future<ClassType>;
template class unique_future<ClassType&>;

View file

@ -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
// <http://www.gnu.org/licenses/>.
#include <future>
#include <thread>
#include <testsuite_performance.h>
void poll(std::shared_future<void> f)
{
while (!f.is_ready())
{ }
}
int main()
{
using namespace __gnu_test;
time_counter time;
resource_counter resource;
const int n = 20;
std::promise<void> p;
std::shared_future<void> 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;
}