]> Creatis software - cpPlugins.git/commitdiff
Merge branch 'master' of ssh://git.creatis.insa-lyon.fr/cpPlugins
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 15 Oct 2015 15:45:35 +0000 (10:45 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 15 Oct 2015 15:45:35 +0000 (10:45 -0500)
appli/examples/CMakeLists.txt
appli/examples/example_Test_async.cxx [new file with mode: 0644]
lib/third_party/Pluma/DLibrary.cpp

index 517433382de2b41597ade8a1093b227a3355b065..b76208835a521e9393bf14002c4629e94d4a51f0 100644 (file)
@@ -55,6 +55,7 @@ SET(
   NOPLUGINS_EXAMPLES_PROGRAMS
   example_BaseInteractorStyle
   example_ContourWidget
+  example_Test_async
   ## example_Test_DoubleClick
   ## example_ExtractDICOMSeries
   ## example_ImageGaussianModelEstimator
diff --git a/appli/examples/example_Test_async.cxx b/appli/examples/example_Test_async.cxx
new file mode 100644 (file)
index 0000000..e3cfd99
--- /dev/null
@@ -0,0 +1,76 @@
+#include <future>
+#include <iostream>
+#ifdef WIN32
+#include <windows.h>
+#else
+#endif
+
+#ifdef WIN32
+#define mysleep Sleep(2000);
+#else
+#define mysleep usleep(2000);
+#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()
+  {
+
+    std::cout << "called from async" << std::endl;
+    this->state.insert(this->it ,10);
+  }
+
+  std::string returned_from_async() {
+    mysleep;
+    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 923d825272c3538052e47e6e3c03d93169fb457d..14516ba74e42ef82bfabbdfec02b43a0370ff3fe 100644 (file)
@@ -51,7 +51,7 @@ DLibrary* DLibrary::load(const std::string& path){
           throw std::runtime_error(\r
             std::string( "Failed to load library \"" ) +\r
             path +\r
-            std::string( "\"." );\r
+            std::string( "\"." )\r
             );\r
           return NULL;\r
         }\r