Library: thread self recognition feature defined (#1054)
This commit is contained in:
parent
458fda4058
commit
d74f1447f3
3 changed files with 99 additions and 4 deletions
|
|
@ -80,7 +80,7 @@ namespace backend {
|
|||
* # failures in the thread function
|
||||
* The operation started in the new thread is protected by a top-level catch block.
|
||||
* Error states or caught exceptions can be propagated through the lumiera_error
|
||||
* state flag, when using the \c join() facility. By invoking \join().maybeThrow()
|
||||
* state flag, when using ThreadJoinable::join(). By invoking `join().maybeThrow()`
|
||||
* on a join-able thread, exceptions can be propagated.
|
||||
* @note any errorstate or caught exception detected on termination of a standard
|
||||
* async Thread is considered a violation of policy and will result in emergency
|
||||
|
|
@ -221,6 +221,13 @@ namespace backend {
|
|||
////////////////////////////////////////////////////////TICKET #1054 : consider to call safeguard here, to ensure this is called from within the thread
|
||||
lumiera_thread_sync ();
|
||||
}
|
||||
|
||||
protected:
|
||||
bool
|
||||
invokedWithinThread()
|
||||
{
|
||||
UNIMPLEMENTED ("thread self recognition");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,8 @@
|
|||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
|
||||
#include "lib/symbol.hpp"
|
||||
#include "backend/thread-wrapper.hpp"
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/sync.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
|
@ -126,7 +124,7 @@ namespace test {
|
|||
, bind (&ThreadWrapperJoin_test::theAction, this, DESTRUCTION_CODE)
|
||||
);
|
||||
|
||||
CHECK (!thread2.join().isValid() ); // can check success without throwing
|
||||
CHECK (not thread2.join().isValid()); // can check success without throwing
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
90
tests/backend/thread-wrapper-self-recognition-test.cpp
Normal file
90
tests/backend/thread-wrapper-self-recognition-test.cpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
ThreadWrapperSelfRecognitionTest(Test) - detect when code is running within a thread
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2017, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
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/test/test-helper.hpp"
|
||||
|
||||
#include "backend/thread-wrapper.hpp"
|
||||
#include "lib/error.hpp"
|
||||
|
||||
using test::Test;
|
||||
|
||||
|
||||
|
||||
namespace backend {
|
||||
namespace test {
|
||||
|
||||
using lumiera::error::LUMIERA_ERROR_LOGIC;
|
||||
namespace {
|
||||
|
||||
class TestThread
|
||||
: Thread
|
||||
{
|
||||
void
|
||||
doIt()
|
||||
{
|
||||
CHECK (invocation_happens_within_this_thread());
|
||||
}
|
||||
|
||||
public:
|
||||
TestThread()
|
||||
: Thread{"test Thread self recognition", [&]() { doIt(); }}
|
||||
{ }
|
||||
|
||||
bool
|
||||
invocation_happens_within_this_thread()
|
||||
{
|
||||
return invokedWithinThread();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
/******************************************************//**
|
||||
* @test verify the ability of a thread to detect code
|
||||
* executing within the thread itself.
|
||||
*
|
||||
* @see Thread::invokedWithinThread()
|
||||
* @see proc::control::DispatcherLoop::stateIsSynched()
|
||||
*/
|
||||
class ThreadWrapperSelfRecognitionTest_test : public Test
|
||||
{
|
||||
|
||||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
TestThread testThread;
|
||||
|
||||
CHECK (not testThread.invocation_happens_within_this_thread());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Register this test class... */
|
||||
LAUNCHER (ThreadWrapperSelfRecognitionTest_test, "function common");
|
||||
|
||||
|
||||
|
||||
}} // namespace backend::test
|
||||
Loading…
Reference in a new issue