1 /* Copyright 2009-2016 Francesco Biscani (bluescarni@gmail.com) 2 3 This file is part of the Piranha library. 4 5 The Piranha library is free software; you can redistribute it and/or modify 6 it under the terms of either: 7 8 * the GNU Lesser General Public License as published by the Free 9 Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 or 13 14 * the GNU General Public License as published by the Free Software 15 Foundation; either version 3 of the License, or (at your option) any 16 later version. 17 18 or both in parallel, as here. 19 20 The Piranha library is distributed in the hope that it will be useful, but 21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23 for more details. 24 25 You should have received copies of the GNU General Public License and the 26 GNU Lesser General Public License along with the Piranha library. If not, 27 see https://www.gnu.org/licenses/. */ 28 29 #include "../src/init.hpp" 30 31 #define BOOST_TEST_MODULE init_test 32 #include <boost/test/included/unit_test.hpp> 33 34 #include "../src/config.hpp" 35 #include "../src/settings.hpp" 36 #include "../src/thread_pool.hpp" 37 38 using namespace piranha; 39 40 struct dummy { ~dummydummy41 ~dummy() 42 { 43 // NOTE: cannot use BOOST_CHECK here because this gets invoked outside the test case. 44 piranha_assert(shutdown()); 45 } 46 }; 47 48 static dummy d; 49 BOOST_AUTO_TEST_CASE(init_main_test)50BOOST_AUTO_TEST_CASE(init_main_test) 51 { 52 settings::set_n_threads(3); 53 // Multiple concurrent constructions. 54 auto f0 = thread_pool::enqueue(0, []() { init(); }); 55 auto f1 = thread_pool::enqueue(1, []() { init(); }); 56 auto f2 = thread_pool::enqueue(2, []() { init(); }); 57 f0.wait(); 58 f1.wait(); 59 f2.wait(); 60 BOOST_CHECK(!shutdown()); 61 BOOST_CHECK_EQUAL(piranha_init_statics<>::s_failed.load(), 2u); 62 } 63