Commit 142a6105 authored by Hossain Mahmud's avatar Hossain Mahmud Committed by Christian Schulte zu Berge
Browse files

yet another unsuccessful attempt :(

parent 609b8375
......@@ -37,37 +37,47 @@
using namespace campvis;
class DummyTestProcessor : public AbstractProcessor {
DummyTestProcessor () {}
DummyTestProcessor () {
_invalidateExternally = false;
_level = AbstractProcessor::InvalidationLevel::VALID;
~DummyTestProcessor () {}
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "DummyTestProcessor"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "A dummy processor for the testing purposes only."; };
/// \see AbstractProcessor::getAuthor()
virtual const std::string getAuthor() const { return "Hossain Mahmud <>"; };
/// \see AbstractProcessor::getProcessorState()
virtual ProcessorState getProcessorState() const { return AbstractProcessor::TESTING; };
/// \see AbstractProcessor::updateResult()
virtual void updateResult(DataContainer& dataContainer) {
dataContainer.addData("ImageData", new ImageData(2, tgt::svec3(1,2,3), 4));
* Even if I comment out the next IF clause, it still remain invalid!!
* shouldn't the process() set it back to ::VALID if no invalidation
* occurs i.e. the queue is empty!!
// this->invalidate(_level);
void lockProcessor() {
void unlockProcessor() {
void setExternalInvalidation(bool status, AbstractProcessor::InvalidationLevel level) {
_invalidateExternally = status;
_level = level;
* Okay, What's the problem here!! if we want to do the invalidation in the updateResult() only,
* things doesn't work. :@
//void process(DataContainer& data, bool unlockInExtraThread=false) {
// AbstractProcessor::process(data, unlockInExtraThread);
// std::this_thread::yield();
bool _invalidateExternally;
AbstractProcessor::InvalidationLevel _level;
......@@ -97,20 +107,6 @@ protected:
DummyTestProcessor _processor1, _processor2;
void callProcess(DummyTestProcessor& processor, DataContainer& dataContainer) {
printf("entering cprocess\n");
printf("going to bed\n");
printf("leaving cprocess\n");
void callInvalidate(DummyTestProcessor& processor, AbstractProcessor::InvalidationLevel level) {
printf("entering cinvalidate\n");
printf("leaving cinvalidate\n");
* Tests invalidation of data
......@@ -118,54 +114,8 @@ TEST_F(AbstractProcessorTest, invalidationTest) {
EXPECT_EQ(AbstractProcessor::InvalidationLevel::VALID, this->_processor1.getInvalidationLevel());
//this->_processor1.lockProcessor(); //this doesn't work. AbstractProcessor::lockProcessor():while doesn't end
this->_processor1.setExternalInvalidation(true, AbstractProcessor::InvalidationLevel::INVALID_RESULT);
EXPECT_EQ(AbstractProcessor::InvalidationLevel::VALID, this->_processor1.getInvalidationLevel());
std::thread first(callProcess, this->_processor1, this->_dataContainer);
std::thread second(callInvalidate, this->_processor1, AbstractProcessor::InvalidationLevel::INVALID_RESULT);
EXPECT_EQ(AbstractProcessor::InvalidationLevel::VALID, this->_processor1.getInvalidationLevel());
EXPECT_NE(AbstractProcessor::InvalidationLevel::VALID, this->_processor1.getInvalidationLevel());
Look, there's no easy way to do this. I'm working on a project that is
inherently multi threaded. Events come in from the operating system and
I have to process them concurrently.
The simplest way to deal with testing complex, multi threaded application
code is this: If its too complex to test, you're doing it wrong. If you
have a single instance that has multiple threads acting upon it, and you
can't test situations where these threads step all over each other, then
your design needs to be redone. Its both as simple and as complex as this.
There are many ways to program for multi threading that avoids threads
running through instances at the same time. The simplest is to make all
your objects immutable. Of course, that's not usually possible. So you
have to identify those places in your design where threads interact
with the same instance and reduce the number of those places. By doing
this, you isolate a few classes where multi threading actually occurs,
reducing the overall complexity of testing your system.
But you have to realize that even by doing this you still can't test
every situation where two threads step on each other. To do that, you'd
have to run two threads concurrently in the same test, then control
exactly what lines they are executing at any given moment. The best you
can do is simulate this situation. But this might require you to code
specifically for testing, and that's at best a half step towards a true
Probably the best way to test code for threading issues is through
static analysis of the code. If your threaded code doesn't follow a
finite set of thread safe patterns, then you might have a problem. I
believe Code Analysis in VS does contain some knowledge of threading,
but probably not much.
Look, as things stand currently (and probably will stand for a good time
to come), the best way to test multi threaded apps is to reduce the
complexity of threaded code as much as possible. Minimize areas where
threads interact, test as best as possible, and use code analysis to
identify danger areas.
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment