/* SyncLocking(Test) - check the monitor object based locking Copyright (C) Lumiera.org 2008, Hermann Vosseler This program 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 of the License, or (at your option) any later version. This program 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 program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *****************************************************/ #include "lib/test/run.hpp" #include "lib/error.hpp" #include "lib/sync.hpp" #include "backend/thread-wrapper.hpp" #include #include using std::bind; using std::cout; using test::Test; namespace lib { namespace test{ namespace { // private test classes and data... const uint NUM_COUNTERS = 20; ///< number of independent counters to increment in parallel const uint NUM_THREADS = 10; ///< number of threads trying to increment these counters const uint MAX_PAUSE = 10000; ///< maximum delay implemented as empty counting loop const uint MAX_SUM = 1000; ///< trigger when to finish incrementing const uint MAX_INC = 10; ///< maximum increment on each step class Victim : public Sync { volatile uint cnt_[NUM_COUNTERS]; volatile uint step_; ///< @note stored as instance variable void pause () { Lock guard (this); // note recursive lock for ( uint i=0, lim=(rand() % MAX_PAUSE); i=" << MAX_SUM << "\n"; ourVictim.report(); } } }; /** Register this test class... */ LAUNCHER (SyncLocking_test, "unit common"); }} // namespace lib::test