thread (thread<>::thread(_Callable)): Explicitly use _Callable as template argument for _M_make_shared_data.

2009-02-08  Chris Fairles  <cfairles@gcc.gnu.org>

        * include/std/thread (thread<>::thread(_Callable)): Explicitly use
        _Callable as template argument for _M_make_shared_data.
        * testsuite/30_threads/thread/cons/6.cc: New.
        * testsuite/30_threads/thread/cons/7.cc: New.
        * testsuite/30_threads/thread/cons/8.cc: New.

From-SVN: r144023
This commit is contained in:
Chris Fairles 2009-02-09 00:13:47 +00:00
parent 9a58d4d27c
commit b47f0044ab
5 changed files with 239 additions and 1 deletions

View File

@ -1,3 +1,11 @@
2009-02-08 Chris Fairles <cfairles@gcc.gnu.org>
* include/std/thread (thread<>::thread(_Callable)): Explicitly use
_Callable as template argument for _M_make_shared_data.
* testsuite/30_threads/thread/cons/6.cc: New.
* testsuite/30_threads/thread/cons/7.cc: New.
* testsuite/30_threads/thread/cons/8.cc: New.
2009-02-07 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/30_threads/thread/member: To..

View File

@ -128,7 +128,7 @@ namespace std
template<typename _Callable>
explicit thread(_Callable __f)
: _M_data(_M_make_shared_data(__f))
: _M_data(_M_make_shared_data<_Callable>(__f))
{ _M_start_thread(); }
template<typename _Callable, typename... _Args>

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 "" }
// 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 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
bool f_was_called = false;
void f()
{
f_was_called = true;
}
void test06()
{
bool test __attribute__((unused)) = true;
try
{
std::thread t(f);
t.join();
VERIFY( f_was_called );
}
catch (const std::system_error&)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
}
int main()
{
test06();
return 0;
}

View File

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

View File

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