Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T, typename... Args> threadsafe_lockless_init(void* buf, Args...&& args) {
- new (buf) T(std::forward<Args>(args)...);
- }
- static decltype(threasfe_lockless_init(nullptr, stuff)) init_ptr = &threadsafe_lockless_init<...>; // init before main
- void func() {
- static char buffer[sizeof(T)];
- decltype(init_ptr) init = nullptr;
- InterlockedExchangePointer(&init_ptr, init);
- if (init)
- init(buffer, ...);
- // win
- }
Advertisement
Add Comment
Please, Sign In to add comment