mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-08 19:20:44 +08:00
all.h (compare_type_to_native_type_sizes): To...
2009-02-12 Benjamin Kosnik <bkoz@redhat.com> * testsuite/util/thread/all.h (compare_type_to_native_type_sizes): To... (compare_type_to_native_type): ...this, add alignment check. * testsuite/30_threads/condition_variable_any/native_handle/ typesizes.cc: Modify as above. * testsuite/30_threads/mutex/native_handle/typesizes.cc: Same. * testsuite/30_threads/timed_mutex/native_handle/typesizes.cc: Same. * testsuite/30_threads/thread/native_handle/typesizes.cc: Same. * testsuite/30_threads/recursive_mutex/native_handle/typesizes.cc: Same. * testsuite/30_threads/condition_variable/native_handle/ typesizes.cc: Same. * testsuite/30_threads/recursive_timed_mutex/native_handle/ typesizes.cc: Same. * testsuite/30_threads/thread/cons/1.cc: Add comments. * testsuite/30_threads/thread/cons/2.cc: Same. * testsuite/30_threads/thread/cons/3.cc: Same. * testsuite/30_threads/thread/cons/4.cc: Same. * testsuite/30_threads/thread/cons/5.cc: Same. * testsuite/30_threads/thread/cons/6.cc: Same. * testsuite/30_threads/thread/cons/7.cc: Same. * testsuite/30_threads/thread/cons/8.cc: Same. * testsuite/30_threads/thread/cons/9.cc: New. * testsuite/30_threads/thread/cons/moveable.cc: New. * src/condition_variable.cc: Clean up whitespace. * include/std/condition_variable: Same. From-SVN: r144147
This commit is contained in:
parent
49547707b8
commit
f3eb9681f0
92
libstdc++-v3/testsuite/30_threads/thread/cons/9.cc
Normal file
92
libstdc++-v3/testsuite/30_threads/thread/cons/9.cc
Normal file
@ -0,0 +1,92 @@
|
||||
// { 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>
|
||||
|
||||
int total = 0;
|
||||
|
||||
// Functor has internal state.
|
||||
struct moveable
|
||||
{
|
||||
int i;
|
||||
|
||||
moveable() = default;
|
||||
~moveable() = default;
|
||||
moveable(const moveable& c) = delete;
|
||||
moveable& operator=(const moveable&) = delete;
|
||||
|
||||
moveable(int j): i(j) { }
|
||||
moveable(moveable&& m): i(m.i) { }
|
||||
|
||||
void operator()() const { total += i; }
|
||||
};
|
||||
|
||||
// Two threads called by same functor type, different functor objects
|
||||
// that have different state. Make sure each thread calls the correct
|
||||
// functor.
|
||||
void test09()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
try
|
||||
{
|
||||
// first
|
||||
moveable m1(60);
|
||||
std::thread t1(std::move(m1));
|
||||
t1.join();
|
||||
VERIFY( total == 60 );
|
||||
|
||||
// second
|
||||
moveable m2(600);
|
||||
std::thread t2(std::move(m2));
|
||||
t2.join();
|
||||
VERIFY( total == 660 ); // Not 120...
|
||||
}
|
||||
catch (const std::system_error&)
|
||||
{
|
||||
VERIFY( false );
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
VERIFY( false );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test09();
|
||||
return 0;
|
||||
}
|
88
libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc
Normal file
88
libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc
Normal 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 "" }
|
||||
|
||||
// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// 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 <utility>
|
||||
#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 { }
|
||||
};
|
||||
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
moveable m;
|
||||
std::thread b(std::move(m));
|
||||
std::thread::id id_initial = b.get_id();
|
||||
VERIFY( b.joinable() );
|
||||
VERIFY( id_initial != std::thread::id() );
|
||||
|
||||
// copy move construct
|
||||
// copied new thread old id, original thread default id
|
||||
std::thread c(std::move(b));
|
||||
VERIFY( c.joinable() );
|
||||
VERIFY( c.get_id() == id_initial );
|
||||
VERIFY( !b.joinable() );
|
||||
VERIFY( b.get_id() == std::thread::id() );
|
||||
|
||||
// copy move assign
|
||||
std::thread d;
|
||||
VERIFY( !d.joinable() );
|
||||
VERIFY( d.get_id() == std::thread::id() );
|
||||
d = std::move(c);
|
||||
VERIFY( d.joinable() );
|
||||
VERIFY( d.get_id() == id_initial );
|
||||
VERIFY( !c.joinable() );
|
||||
VERIFY( c.get_id() == std::thread::id() );
|
||||
|
||||
d.join();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user