diff --git a/Sources/Foundation/Thread.swift b/Sources/Foundation/Thread.swift index ac1aa0eed4..bb6e166184 100644 --- a/Sources/Foundation/Thread.swift +++ b/Sources/Foundation/Thread.swift @@ -323,10 +323,16 @@ open class Thread : NSObject { #if os(Windows) open var stackSize: Int { get { + // If we set a stack size for this thread. + // Otherwise, query the actual limits. + guard _attr.dwThreadStackReservation == 0 else { + return Int(_attr.dwThreadStackReservation) + } var ulLowLimit: ULONG_PTR = 0 var ulHighLimit: ULONG_PTR = 0 GetCurrentThreadStackLimits(&ulLowLimit, &ulHighLimit) - return Int(ulLowLimit) + // Return the reserved stack span. + return Int(ulHighLimit - ulLowLimit) } set { _attr.dwThreadStackReservation = DWORD(newValue)