[Bf-blender-cvs] [fb6f1aa12f9] blender2.7: Fix Cycles Embree crash on macOS, due to too small thread stack size.

Brecht Van Lommel noreply at git.blender.org
Thu Feb 14 17:23:39 CET 2019


Commit: fb6f1aa12f945c6a17ca96f402dec2f6bce81463
Author: Brecht Van Lommel
Date:   Thu Feb 14 14:37:57 2019 +0100
Branches: blender2.7
https://developer.blender.org/rBfb6f1aa12f945c6a17ca96f402dec2f6bce81463

Fix Cycles Embree crash on macOS, due to too small thread stack size.

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

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 4d30e3f564f..f3c6077f6b7 100644
--- a/intern/cycles/util/util_thread.cpp
+++ b/intern/cycles/util/util_thread.cpp
@@ -26,7 +26,17 @@ thread::thread(function<void()> run_cb, int node)
     joined_(false),
 	node_(node)
 {
-	thread_ = std::thread(&thread::run, this);
+#ifdef __APPLE__
+	/* Set the stack size to 2MB to match Linux. The default 512KB on macOS is
+	 * too small for Embree, and consistent stack size also makes things more
+	 * predictable in general. */
+	pthread_attr_t attribute;
+	pthread_attr_init(&attribute);
+	pthread_attr_setstacksize(&attribute, 1024*1024*2);
+	pthread_create(&pthread_id, &attribute, run, (void*)this);
+#else
+	std_thread = std::thread(&thread::run, this);
+#endif
 }
 
 thread::~thread()
@@ -49,13 +59,17 @@ void *thread::run(void *arg)
 bool thread::join()
 {
 	joined_ = true;
+#ifdef __APPLE__
+	return pthread_join(pthread_id, NULL) == 0;
+#else
 	try {
-		thread_.join();
+		std_thread.join();
 		return true;
 	}
 	catch (const std::system_error&) {
 		return false;
 	}
+#endif
 }
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/util/util_thread.h b/intern/cycles/util/util_thread.h
index 9ae9af25e6b..793d44130b6 100644
--- a/intern/cycles/util/util_thread.h
+++ b/intern/cycles/util/util_thread.h
@@ -41,8 +41,8 @@ typedef std::mutex thread_mutex;
 typedef std::unique_lock<std::mutex> thread_scoped_lock;
 typedef std::condition_variable thread_condition_variable;
 
-/* own pthread based implementation, to avoid boost version conflicts with
- * dynamically loaded blender plugins */
+/* Own thread implementation similar to std::thread, so we can set a
+ * custom stack size on macOS. */
 
 class thread {
 public:
@@ -56,7 +56,11 @@ public:
 
 protected:
 	function<void()> run_cb_;
-	std::thread thread_;
+#ifdef __APPLE__
+	pthread_t pthread_id;
+#else
+	std::thread std_thread;
+#endif
 	bool joined_;
 	int node_;
 };



More information about the Bf-blender-cvs mailing list