>
void* start_routine(void* ptr)
{
P* p = reinterpret_cast(ptr);
(p->first->*(p->second))(); // Call member function pointer
delete p;
return nullptr;
}
class NativeThread {
pthread_t thread;
public:
template>
explicit NativeThread(void(T::*fun)(), T* obj) {
pthread_attr_t attr_storage, *attr = &attr_storage;
pthread_attr_init(attr);
pthread_attr_setstacksize(attr, TH_STACK_SIZE);
pthread_create(&thread, attr, start_routine, new P(obj, fun));
}
void join() { pthread_join(thread, nullptr); }
};
} // namespace Stockfish
#else // Default case: use STL classes
namespace Stockfish {
using NativeThread = std::thread;
} // namespace Stockfish
#endif
#endif // #ifndef THREAD_WIN32_OSX_H_INCLUDED