Skip to content

Commit 9db5b82

Browse files
authored
Windows: correct Thread.stackSize computation (#5306)
1 parent eef6f00 commit 9db5b82

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/Foundation/Thread.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,16 @@ open class Thread : NSObject {
335335
#if os(Windows)
336336
open var stackSize: Int {
337337
get {
338+
// If we set a stack size for this thread.
339+
// Otherwise, query the actual limits.
340+
guard _attr.dwThreadStackReservation == 0 else {
341+
return Int(_attr.dwThreadStackReservation)
342+
}
338343
var ulLowLimit: ULONG_PTR = 0
339344
var ulHighLimit: ULONG_PTR = 0
340345
GetCurrentThreadStackLimits(&ulLowLimit, &ulHighLimit)
341-
return Int(ulLowLimit)
346+
// Return the reserved stack span.
347+
return Int(ulHighLimit - ulLowLimit)
342348
}
343349
set {
344350
_attr.dwThreadStackReservation = DWORD(newValue)

0 commit comments

Comments
 (0)