forked from dealii/dealii
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: add a test for Threads::InitializationCheck
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// --------------------------------------------------------------------- | ||
// | ||
// Copyright (C) 2005 - 2021 by the deal.II authors | ||
// | ||
// This file is part of the deal.II library. | ||
// | ||
// The deal.II library is free software; you can use it, redistribute | ||
// it, and/or modify it under the terms of the GNU Lesser General | ||
// Public License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// The full text of the license can be found in the file LICENSE.md at | ||
// the top level directory of deal.II. | ||
// | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
// check numbers::is_finite | ||
|
||
#include <deal.II/base/initialization_check.h> | ||
|
||
#include <iostream> | ||
|
||
#include "../tests.h" | ||
|
||
using namespace dealii; | ||
|
||
class Consumer | ||
{ | ||
public: | ||
void | ||
do_something() | ||
{ | ||
deallog << "called do_something" << std::endl; | ||
initialization_check.check_and_initialize( | ||
[&]() { deallog << "called initializer" << std::endl; }); | ||
} | ||
|
||
private: | ||
Threads::InitializationCheck initialization_check; | ||
}; | ||
|
||
int | ||
main() | ||
{ | ||
initlog(); | ||
|
||
deallog << "consumer_1:" << std::endl; | ||
Consumer consumer_1; | ||
consumer_1.do_something(); | ||
consumer_1.do_something(); | ||
|
||
deallog << "consumer_2 (copy constructed, already initialized):" << std::endl; | ||
auto consumer_2 = consumer_1; | ||
consumer_2.do_something(); | ||
|
||
deallog << "consumer_3:" << std::endl; | ||
Consumer consumer_3; | ||
consumer_3.do_something(); | ||
deallog << "consumer_3 (copy assignment, already initialized):" << std::endl; | ||
consumer_3 = consumer_1; | ||
consumer_3.do_something(); | ||
deallog << "consumer_3 (move assignment, uninitialized):" << std::endl; | ||
consumer_3 = Consumer(); | ||
consumer_3.do_something(); | ||
|
||
deallog << "OK!" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
DEAL::consumer_1: | ||
DEAL::called do_something | ||
DEAL::called initializer | ||
DEAL::called do_something | ||
DEAL::consumer_2 (copy constructed, already initialized): | ||
DEAL::called do_something | ||
DEAL::consumer_3: | ||
DEAL::called do_something | ||
DEAL::called initializer | ||
DEAL::consumer_3 (copy assignment, already initialized): | ||
DEAL::called do_something | ||
DEAL::consumer_3 (move assignment, uninitialized): | ||
DEAL::called do_something | ||
DEAL::called initializer | ||
DEAL::OK! |