Skip to content

Commit d7af652

Browse files
authored
Merge pull request #2309 from Lukasa/cb-thread-name
Foundation: correctly read thread name
2 parents 3bf64a9 + 6214772 commit d7af652

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Foundation/Thread.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,12 @@ open class Thread : NSObject {
251251
}
252252

253253
open var name: String? {
254-
didSet {
254+
get {
255+
return _name
256+
}
257+
set {
255258
if let thread = _thread {
256-
_CFThreadSetName(thread, name ?? "" )
259+
_CFThreadSetName(thread, newValue ?? "" )
257260
}
258261
}
259262
}

TestFoundation/TestThread.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,17 @@ class TestThread : XCTestCase {
6868

6969
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
7070
func test_threadName() {
71-
// No name is set initially
72-
XCTAssertNil(Thread.current.name)
73-
7471
#if os(Linux) // Linux sets the initial thread name to the process name.
72+
XCTAssertEqual(Thread.current.name, "TestFoundation")
7573
XCTAssertEqual(Thread.current._name, "TestFoundation")
7674
#else
75+
// No name is set initially
76+
XCTAssertEqual(Thread.current.name, "")
7777
XCTAssertEqual(Thread.current._name, "")
7878
#endif
7979
Thread.current.name = "mainThread"
8080
XCTAssertEqual(Thread.mainThread.name, "mainThread")
81+
XCTAssertEqual(Thread.mainThread._name, "mainThread")
8182

8283
let condition = NSCondition()
8384
condition.lock()

0 commit comments

Comments
 (0)