mirror of
https://github.com/sockspls/badfish
synced 2025-07-13 12:39:16 +00:00
Increase thread stack for OS X (#2035)
On OS X threads other than the main thread are created with a reduced stack size of 512KB by default, this is dangerously low for deep searches, so adjust it to TH_STACK_SIZE. The implementation calls pthread_create() with proper stack size parameter. Verified for no regression at STC enabling the patch on all platforms where pthread is supported. LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 50873 W: 9768 L: 9700 D: 31405 No functional change.
This commit is contained in:
parent
b8efa0daac
commit
bad18bccb6
3 changed files with 48 additions and 6 deletions
|
@ -32,7 +32,7 @@
|
||||||
#include "../movegen.h"
|
#include "../movegen.h"
|
||||||
#include "../position.h"
|
#include "../position.h"
|
||||||
#include "../search.h"
|
#include "../search.h"
|
||||||
#include "../thread_win32.h"
|
#include "../thread_win32_osx.h"
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
#include "../uci.h"
|
#include "../uci.h"
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread_win32.h"
|
#include "thread_win32_osx.h"
|
||||||
|
|
||||||
|
|
||||||
/// Thread class keeps together all the thread-related stuff. We use
|
/// Thread class keeps together all the thread-related stuff. We use
|
||||||
|
@ -46,7 +46,7 @@ class Thread {
|
||||||
ConditionVariable cv;
|
ConditionVariable cv;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
bool exit = false, searching = true; // Set before starting std::thread
|
bool exit = false, searching = true; // Set before starting std::thread
|
||||||
std::thread stdThread;
|
NativeThread stdThread;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Thread(size_t);
|
explicit Thread(size_t);
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef THREAD_WIN32_H_INCLUDED
|
#ifndef THREAD_WIN32_OSX_H_INCLUDED
|
||||||
#define THREAD_WIN32_H_INCLUDED
|
#define THREAD_WIN32_OSX_H_INCLUDED
|
||||||
|
|
||||||
/// STL thread library used by mingw and gcc when cross compiling for Windows
|
/// STL thread library used by mingw and gcc when cross compiling for Windows
|
||||||
/// relies on libwinpthread. Currently libwinpthread implements mutexes directly
|
/// relies on libwinpthread. Currently libwinpthread implements mutexes directly
|
||||||
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(_MSC_VER)
|
#if defined(_WIN32) && !defined(_MSC_VER)
|
||||||
|
|
||||||
|
@ -67,4 +68,45 @@ typedef std::condition_variable ConditionVariable;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // #ifndef THREAD_WIN32_H_INCLUDED
|
/// On OSX threads other than the main thread are created with a reduced stack
|
||||||
|
/// size of 512KB by default, this is dangerously low for deep searches, so
|
||||||
|
/// adjust it to TH_STACK_SIZE. The implementation calls pthread_create() with
|
||||||
|
/// proper stack size parameter.
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
static const size_t TH_STACK_SIZE = 2 * 1024 * 1024;
|
||||||
|
|
||||||
|
template <class T, class P = std::pair<T*, void(T::*)()>>
|
||||||
|
void* start_routine(void* ptr)
|
||||||
|
{
|
||||||
|
P* p = reinterpret_cast<P*>(ptr);
|
||||||
|
(p->first->*(p->second))(); // Call member function pointer
|
||||||
|
delete p;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
class NativeThread {
|
||||||
|
|
||||||
|
pthread_t thread;
|
||||||
|
|
||||||
|
public:
|
||||||
|
template<class T, class P = std::pair<T*, void(T::*)()>>
|
||||||
|
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<T>, new P(obj, fun));
|
||||||
|
}
|
||||||
|
void join() { pthread_join(thread, NULL); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#else // Default case: use STL classes
|
||||||
|
|
||||||
|
typedef std::thread NativeThread;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef THREAD_WIN32_OSX_H_INCLUDED
|
Loading…
Add table
Reference in a new issue