Advertisement
dvulakh

multithread.h

May 10th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 41.16 KB | None | 0 0
  1.  
  2. #ifndef MULTITHREAD_H
  3. #define MULTITHREAD_H
  4.  
  5. #include <shared_mutex>
  6. #include <cstdarg>
  7. #include <thread>
  8. #include <chrono>
  9. #include <atomic>
  10. #include <mutex>
  11.  
  12. using namespace std;
  13.  
  14. #define TPLUS(t0) (chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now() - (t0)) / 1000000000.0)
  15. #define SLEEP(ms) this_thread::sleep_for(chrono::milliseconds(ms))
  16. #define JOINABLE(...) threads.push_back(new thread(__VA_ARGS__))
  17. #define JOIN for(thread* t : threads) { t->join(), delete t; }
  18. #define SPAWN(...) thread(__VA_ARGS__).detach()
  19. #define L(T, F) &T::F, this
  20.  
  21. #define DOUBLE atomic<double>
  22. #define BOOL atomic<bool>
  23. #define INT atomic<int>
  24. #define A(T) atomic<T>
  25.  
  26. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement