fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <random>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <chrono>
  8. #include <ctime>
  9. #define _USE_MATH_DEFINES
  10. #include <math.h>
  11. #include <time.h>
  12. #include <iostream>
  13. #include <thread>
  14. #include <atomic>
  15. #include <vector>
  16. #include <mutex>
  17.  
  18. using namespace std;
  19.  
  20. struct Test_S
  21. {
  22. vector<double> test_vector1;
  23. vector<double> test_vector2;
  24. mutex test_mtx;
  25. };
  26.  
  27. class Base
  28. {
  29. public:
  30. Base() {}
  31. void domath() { cout << "base function\n"; }
  32. int i;
  33. };
  34.  
  35. class Derived1 : public Base
  36. {
  37. public:
  38. Derived1() {}
  39. void domath1(Test_S* test_s) const { test_s->test_vector1.push_back(1); }
  40. };
  41.  
  42. class Derived2 : public Base
  43. {
  44. public:
  45. Derived2() {}
  46. void domath2(Test_S* test_s) const { test_s->test_vector2.push_back(2); }
  47. };
  48.  
  49. int main()
  50. {
  51. Base base;
  52. Derived1 derived1;
  53. Derived2 derived2;
  54.  
  55. Test_S test_s;
  56.  
  57. std::thread t1(&Derived1::domath1, &derived1, &test_s);
  58. std::thread t2(&Derived2::domath2, &derived2, &test_s);
  59.  
  60. t1.join();
  61. t2.join();
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0s 20824KB
stdin
Standard input is empty
stdout
Standard output is empty