From: jose guzman Date: Thu, 15 Oct 2015 08:18:33 +0000 (+0200) Subject: async test X-Git-Tag: v0.1~331^2^2 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=1e2c41f2026670ce3d4b5a0bbfb201f312e2e20b;p=cpPlugins.git async test --- diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index afbe041..ee0d4fe 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -9,6 +9,7 @@ SET( example_LoadPlugins example_ReadWriteImage example_View2DImage + example_Test_async ##example_MarchingCubes ##example_OtsuFilter ##example_RGBImageToHSVChannels diff --git a/appli/examples/example_Test_async.cxx b/appli/examples/example_Test_async.cxx new file mode 100644 index 0000000..efc9b94 --- /dev/null +++ b/appli/examples/example_Test_async.cxx @@ -0,0 +1,79 @@ +#include +#include +#ifdef WIN32 +#include +#else +#endif + +class Test +{ +private: + std::vector state; + std::vector::iterator it; + std::vector isAvailable; +public: + Test() + { + this->it = this->state.begin(); + } + + void called_from_async() + { +#ifdef WIN32 + Sleep(2000); +#else + usleep(2000 * 1000); +#endif + std::cout << "called from async" << std::endl; + this->state.insert(this->it ,10); + } + + std::string returned_from_async() { +#ifdef WIN32 + Sleep(2000); +#else + usleep(2000 * 1000); +#endif + //std::cout << "Async call" << std::endl; + return "Async call"; + } + + template + void print_results(ASYNC &f) + { + std::string result = f.get(); + std::cout << result.c_str() << std::endl; + } + + int getState(int pos) + { + return this->state.at(pos); + } + + int getStateSize() + { + return this->state.size(); + } +}; + +int main() { + Test test; + std::future result(std::async(&Test::called_from_async, &test)); + + auto f1 = std::async(std::launch::async, &Test::returned_from_async, &test); + + std::cout << "Message from main." << std::endl; + do + { + std::cout << test.getStateSize(); + } while (test.getStateSize()<1); + +#ifdef _DEBUG + auto i = 0; + std::cout << "wait for close"; + std::cin >> i; +#endif + + return 0; + +} \ No newline at end of file diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index 4498a2b..c3b1355 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -289,6 +289,7 @@ GetLookupTable( unsigned int i ) const else return( NULL ); */ + return 0; } // ------------------------------------------------------------------------- @@ -335,6 +336,7 @@ GetMaxWindow( unsigned int i ) const image->GetScalarRange( r ); return( r[ 1 ] - r[ 0 ] ); */ + return 0; } // ------------------------------------------------------------------------- @@ -351,6 +353,7 @@ GetMinLevel( unsigned int i ) const image->GetScalarRange( r ); return( r[ 0 ] ); */ + return 0; } // ------------------------------------------------------------------------- @@ -367,6 +370,7 @@ GetMaxLevel( unsigned int i ) const image->GetScalarRange( r ); return( r[ 1 ] ); */ + return 0; } // ------------------------------------------------------------------------- @@ -381,6 +385,7 @@ GetWindow( unsigned int i ) const else return( double( 0 ) ); */ + return 0; } // ------------------------------------------------------------------------- @@ -395,6 +400,7 @@ GetLevel( unsigned int i ) const else return( double( 0 ) ); */ + return 0; } // -------------------------------------------------------------------------