]> Creatis software - cpPlugins.git/commitdiff
async test
authorjose guzman <jose@gmail.com>
Thu, 15 Oct 2015 08:18:33 +0000 (10:18 +0200)
committerjose guzman <jose@gmail.com>
Thu, 15 Oct 2015 08:18:33 +0000 (10:18 +0200)
appli/examples/CMakeLists.txt
appli/examples/example_Test_async.cxx [new file with mode: 0644]
lib/cpExtensions/Visualization/MPRActors.cxx

index afbe04113da493603eea136ba984915891356b58..ee0d4fe8440295bcc5e4846fb51940136bd193f3 100644 (file)
@@ -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 (file)
index 0000000..efc9b94
--- /dev/null
@@ -0,0 +1,79 @@
+#include <future>
+#include <iostream>
+#ifdef WIN32
+#include <windows.h>
+#else
+#endif
+
+class Test
+{
+private:
+  std::vector<int> state;
+  std::vector<int>::iterator it;
+  std::vector<bool> 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<class ASYNC>
+  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<void> 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
index 4498a2ba8120d5c18a23db065e75d488bc672028..c3b1355fcf8bc6834a8181fc12a06aca777a1b2b 100644 (file)
@@ -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;
 }
 
 // -------------------------------------------------------------------------