Guest User

Untitled

a guest
Oct 22nd, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. template<typename T, typename... Args> threadsafe_lockless_init(void* buf, Args...&& args) {
  2. new (buf) T(std::forward<Args>(args)...);
  3. }
  4. static decltype(threasfe_lockless_init(nullptr, stuff)) init_ptr = &threadsafe_lockless_init<...>; // init before main
  5.  
  6. void func() {
  7. static char buffer[sizeof(T)];
  8. decltype(init_ptr) init = nullptr;
  9. InterlockedExchangePointer(&init_ptr, init);
  10. if (init)
  11. init(buffer, ...);
  12. // win
  13. }
  14.  
Advertisement
Add Comment
Please, Sign In to add comment