[Bf-blender-cvs] [151b5a9a1e5] cycles_embree: Cycles: Raised thread stack size to 1MB for macOS to be consistent with Windows.

Stefan Werner noreply at git.blender.org
Wed Aug 1 23:01:58 CEST 2018


Commit: 151b5a9a1e568476c6886709b460edbf0936f7f7
Author: Stefan Werner
Date:   Wed Aug 1 23:01:56 2018 +0200
Branches: cycles_embree
https://developer.blender.org/rB151b5a9a1e568476c6886709b460edbf0936f7f7

Cycles: Raised thread stack size to 1MB for macOS to be consistent with Windows.

Embree BVH builds would run out of stack space in the default of 512kB.
This means macOS builds have to stay with pthreads and can't use std::thread.

===================================================================

M	intern/cycles/util/util_thread.cpp
M	intern/cycles/util/util_thread.h

===================================================================

diff --git a/intern/cycles/util/util_thread.cpp b/intern/cycles/util/util_thread.cpp
index c66aa484264..9ab43284074 100644
--- a/intern/cycles/util/util_thread.cpp
+++ b/intern/cycles/util/util_thread.cpp
@@ -26,10 +26,19 @@ thread::thread(function<void(void)> run_cb, int group)
     joined_(false),
 	group_(group)
 {
-#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#ifdef CYCLES_USE_STD_THREAD
 	thread_ = std::thread(&thread::run, this);
 #else
+# ifdef __APPLE__
+	/* Set the stack size to 1MB to match other platforms.
+	 * The default of 512kB may be to small. */
+	pthread_attr_t attribute;
+	pthread_attr_init(&attribute);
+	pthread_attr_setstacksize(&attribute,1024*1024*1);
+	pthread_create(&pthread_id_, &attribute, run, (void*)this);
+#  else
 	pthread_create(&pthread_id_, NULL, run, (void*)this);
+#  endif
 #endif
 }
 
@@ -64,7 +73,7 @@ void *thread::run(void *arg)
 bool thread::join()
 {
 	joined_ = true;
-#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#ifdef CYCLES_USE_STD_THREAD
 	try {
 		thread_.join();
 		return true;
diff --git a/intern/cycles/util/util_thread.h b/intern/cycles/util/util_thread.h
index 77b51d37ea0..2972199398b 100644
--- a/intern/cycles/util/util_thread.h
+++ b/intern/cycles/util/util_thread.h
@@ -18,6 +18,12 @@
 #define __UTIL_THREAD_H__
 
 #if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#if !defined(__APPLE__)
+#  define CYCLES_USE_STD_THREAD
+#endif
+#endif
+
+#ifdef CYCLES_USE_STD_THREAD
 #  include <thread>
 #  include <mutex>
 #  include <condition_variable>
@@ -42,7 +48,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#ifdef CYCLES_USE_STD_THREAD
 typedef std::mutex thread_mutex;
 typedef std::unique_lock<std::mutex> thread_scoped_lock;
 typedef std::condition_variable thread_condition_variable;
@@ -66,7 +72,7 @@ public:
 
 protected:
 	function<void(void)> run_cb_;
-#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#ifdef CYCLES_USE_STD_THREAD
 	std::thread thread_;
 #else
 	pthread_t pthread_id_;



More information about the Bf-blender-cvs mailing list