Skip to content

Commit e711a32

Browse files
committed
Address stack size issues in Mac OS builds.
1 parent f69e17c commit e711a32

File tree

8 files changed

+60
-20
lines changed

8 files changed

+60
-20
lines changed

changes.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ should be located in the same directory as this file is.
2929
------------------------------------------------------------------------------
3030

3131

32+
Changes between 3.7.0.7 and 3.7.0.8
33+
===================================
34+
35+
(Note: This version has not been released in binary form, as it does not
36+
feature any changes in functionality over the original 3.7.0 binaries.)
37+
38+
This version constitutes a maintenance update of the POV-Ray 3.7.0 source
39+
code, focused on improving compatibility with Mac OS builds.
40+
41+
Fixed or Mitigated Bugs
42+
-----------------------
43+
44+
- Modify thread creation code to more easily address thread stack size issues
45+
in Mac OS builds (requires Boost 1.50 or later to be effective).
46+
47+
3248
Changes between 3.7.0.6 and 3.7.0.7
3349
===================================
3450

source/backend/configbackend.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@
278278
#define POV_ALLOW_FILE_WRITE(f,t) (1)
279279
#endif
280280

281+
/// @def POV_THREAD_STACK_SIZE
282+
/// Default thread stack size.
283+
///
284+
#ifndef POV_THREAD_STACK_SIZE
285+
#define POV_THREAD_STACK_SIZE (2 * 1024 * 1024)
286+
#endif
287+
288+
/// @def HAVE_BOOST_THREAD_ATTRIBUTES
289+
/// Whether boost::thread::attributes is available (and can be used to set a thread's stack size).
290+
///
291+
#if BOOST_VERSION >= 105000
292+
#define HAVE_BOOST_THREAD_ATTRIBUTES 1
293+
#else
294+
#define HAVE_BOOST_THREAD_ATTRIBUTES 0
295+
#endif
296+
281297
#include "syspovprotobackend.h"
282298

283299
#endif

source/backend/povray.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "backend/povray.h"
4848
#include "backend/control/renderbackend.h"
4949
#include "backend/support/msgutil.h"
50+
#include "backend/support/task.h"
5051
#include "backend/texture/texture.h"
5152

5253
#ifndef DONT_SHOW_IMAGE_LIB_VERSIONS
@@ -593,11 +594,7 @@ boost::thread *povray_init(const boost::function0<void>& threadExit, POVMSAddres
593594
Initialize_Noise();
594595
pov::InitializePatternGenerators();
595596

596-
#ifndef USE_OFFICIAL_BOOST
597-
POV_MainThread = new boost::thread(boost::bind(&MainThreadFunction, threadExit), 1024 * 64);
598-
#else
599-
POV_MainThread = new boost::thread(boost::bind(&MainThreadFunction, threadExit));
600-
#endif
597+
POV_MainThread = Task::NewBoostThread(boost::bind(&MainThreadFunction, threadExit), POV_THREAD_STACK_SIZE);
601598

602599
// we can't depend on boost::thread::yield here since under windows it is not
603600
// guaranteed to give up a time slice [see API docs for Sleep(0)]

source/backend/scene/scene.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "backend/control/renderbackend.h"
4646
#include "backend/scene/scene.h"
4747
#include "backend/scene/objects.h"
48+
#include "backend/support/task.h"
4849
#include "backend/parser/parse.h"
4950
#include "backend/bounding/boundingtask.h"
5051
#include "backend/texture/texture.h"
@@ -438,11 +439,7 @@ void Scene::StartParser(POVMS_Object& parseOptions)
438439
{
439440
// A scene can only be parsed once
440441
if(parserControlThread == NULL)
441-
#ifndef USE_OFFICIAL_BOOST
442-
parserControlThread = new boost::thread(boost::bind(&Scene::ParserControlThread, this), 1024 * 64);
443-
#else
444-
parserControlThread = new boost::thread(boost::bind(&Scene::ParserControlThread, this));
445-
#endif
442+
parserControlThread = Task::NewBoostThread(boost::bind(&Scene::ParserControlThread, this), POV_THREAD_STACK_SIZE);
446443
else
447444
return;
448445

source/backend/scene/view.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "backend/scene/view.h"
4949
#include "backend/render/tracetask.h"
5050
#include "backend/render/radiositytask.h"
51+
#include "backend/support/task.h"
5152
#include "backend/lighting/photons.h"
5253
#include "backend/lighting/radiosity.h"
5354

@@ -681,11 +682,7 @@ void View::StartRender(POVMS_Object& renderOptions)
681682
shared_ptr<std::set<unsigned int> > blockskiplist(new std::set<unsigned int>());
682683

683684
if(renderControlThread == NULL)
684-
#ifndef USE_OFFICIAL_BOOST
685-
renderControlThread = new thread(boost::bind(&View::RenderControlThread, this), 1024 * 64);
686-
#else
687-
renderControlThread = new boost::thread(boost::bind(&View::RenderControlThread, this));
688-
#endif
685+
renderControlThread = Task::NewBoostThread(boost::bind(&View::RenderControlThread, this), POV_THREAD_STACK_SIZE);
689686

690687
viewData.qualitySettings.Quality = clip(renderOptions.TryGetInt(kPOVAttrib_Quality, 9), 0, 9);
691688
viewData.qualitySettings.Quality_Flags = QualityValues[viewData.qualitySettings.Quality];

source/backend/support/task.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ POV_LONG Task::ConsumedCPUTime() const
102102
void Task::Start(const boost::function0<void>& completion)
103103
{
104104
if((done == false) && (taskThread == NULL))
105-
#ifndef USE_OFFICIAL_BOOST
106-
taskThread = new boost::thread(boost::bind(&Task::TaskThread, this, completion), 1024 * 1024 * 2); // TODO - make stack size definable
107-
#else
108-
taskThread = new boost::thread(boost::bind(&Task::TaskThread, this, completion));
109-
#endif
105+
taskThread = NewBoostThread(boost::bind(&Task::TaskThread, this, completion), POV_THREAD_STACK_SIZE);
110106
}
111107

112108
void Task::RequestStop()

source/backend/support/task.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,25 @@ class Task
112112
inline TaskData *GetDataPtr() { return taskData; }
113113

114114
inline POVMSContext GetPOVMSContext() { return povmsContext; }
115+
116+
/// Start a new thread with a given stack size.
117+
template<typename CALLABLE_T>
118+
inline static boost::thread* NewBoostThread(CALLABLE_T func, int stackSize)
119+
{
120+
#if HAVE_BOOST_THREAD_ATTRIBUTES
121+
// boost 1.50 and later provide an official mechanism to set the stack size.
122+
boost::thread::attributes attr;
123+
attr.set_stack_size (stackSize);
124+
return new boost::thread(attr, func);
125+
#elif !defined(USE_OFFICIAL_BOOST)
126+
// Prior to boost 1.50, for some platforms we used an unofficial hacked version of boost to set the stack size.
127+
return new boost::thread(func, stackSize);
128+
#else
129+
// For some platforms the default stack size of older boost versions may suffice.
130+
return new boost::thread(func);
131+
#endif
132+
}
133+
115134
protected:
116135
virtual void Run() = 0;
117136
virtual void Stopped() = 0;

vfe/unix/syspovconfigbackend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
#define NEW_LINE_STRING "\n" // default
4040
#define SYS_DEF_EXT ""
4141

42+
#define POV_THREAD_STACK_SIZE (4 * 1024 * 1024) // twice the usual default
43+
4244
#endif

0 commit comments

Comments
 (0)