Skip to content

Commit fd7c78b

Browse files
committed
COMP: Let Future.get() calls in PoolMultiThreader always return void
`Future` was declared as `std::future<ITK_THREAD_RETURN_TYPE>`, which is platform specific, and caused warnings on some platforms, as reported by Hans Johnson at InsightSoftwareConsortium#5945 : itkPoolMultiThreader.cxx:148:55: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] exceptionHandler.TryAndCatch([this, threadLoop] { m_ThreadInfoArray[threadLoop].Future.get(); }); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Addressed by replacing the public `ThreadPoolInfoStruct` with a private `InternalWorkUnitInfo` struct, which has its `Future` declared as `std::future<void>`.
1 parent badec43 commit fd7c78b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Modules/Core/Common/include/itkPoolMultiThreader.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ class ITKCommon_EXPORT PoolMultiThreader : public MultiThreaderBase
9595
void
9696
SetMaximumNumberOfThreads(ThreadIdType numberOfThreads) override;
9797

98-
struct ThreadPoolInfoStruct : WorkUnitInfo
98+
#ifndef ITK_FUTURE_LEGACY_REMOVE
99+
struct ITK_FUTURE_DEPRECATED(
100+
"PoolMultiThreader now uses a slightly different private `InternalWorkUnitInfo` struct instead!")
101+
ThreadPoolInfoStruct : WorkUnitInfo
99102
{
100103
std::future<ITK_THREAD_RETURN_TYPE> Future;
101104
};
105+
#endif
102106

103107
protected:
104108
PoolMultiThreader();
@@ -107,13 +111,18 @@ class ITKCommon_EXPORT PoolMultiThreader : public MultiThreaderBase
107111
PrintSelf(std::ostream & os, Indent indent) const override;
108112

109113
private:
114+
struct InternalWorkUnitInfo : WorkUnitInfo
115+
{
116+
std::future<void> Future;
117+
};
118+
110119
// Thread pool instance and factory
111120
ThreadPool::Pointer m_ThreadPool{};
112121

113122
/** An array of work unit information containing a work unit id
114123
* (0, 1, 2, .. ITK_MAX_THREADS-1), work unit count, and a pointer
115124
* to void so that user data can be passed to each thread. */
116-
ThreadPoolInfoStruct m_ThreadInfoArray[ITK_MAX_THREADS]{};
125+
InternalWorkUnitInfo m_ThreadInfoArray[ITK_MAX_THREADS]{};
117126

118127
/** Friends of Multithreader.
119128
* ProcessObject is a friend so that it can call PrintSelf() on its

Modules/Core/Common/src/itkPoolMultiThreader.cxx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ PoolMultiThreader::SingleMethodExecute()
132132
{
133133
m_ThreadInfoArray[threadLoop].UserData = m_SingleData;
134134
m_ThreadInfoArray[threadLoop].NumberOfWorkUnits = m_NumberOfWorkUnits;
135-
m_ThreadInfoArray[threadLoop].Future = m_ThreadPool->AddWork(m_SingleMethod, &m_ThreadInfoArray[threadLoop]);
135+
m_ThreadInfoArray[threadLoop].Future = m_ThreadPool->AddWork(
136+
[method = m_SingleMethod, threadInfo = &m_ThreadInfoArray[threadLoop]] { method(threadInfo); });
136137
}
137138

138139
// Now, the parent thread calls this->SingleMethod() itself
@@ -175,8 +176,6 @@ PoolMultiThreader::ParallelizeArray(SizeValueType firstIndex,
175176
{
176177
aFunc(ii);
177178
}
178-
// make this lambda have the same signature as m_SingleMethod
179-
return ITK_THREAD_RETURN_DEFAULT_VALUE;
180179
};
181180

182181
SizeValueType workUnit = 1;
@@ -265,11 +264,8 @@ PoolMultiThreader::ParallelizeImageRegion(unsigned int dimension,
265264
total = splitter->GetSplit(i, splitCount, iRegion);
266265
if (i < total)
267266
{
268-
m_ThreadInfoArray[i].Future = m_ThreadPool->AddWork([funcP, iRegion]() {
269-
funcP(&iRegion.GetIndex()[0], &iRegion.GetSize()[0]);
270-
// make this lambda have the same signature as m_SingleMethod
271-
return ITK_THREAD_RETURN_DEFAULT_VALUE;
272-
});
267+
m_ThreadInfoArray[i].Future =
268+
m_ThreadPool->AddWork([funcP, iRegion]() { funcP(&iRegion.GetIndex()[0], &iRegion.GetSize()[0]); });
273269
}
274270
else
275271
{

0 commit comments

Comments
 (0)