Skip to content

SR-5871: TestThread.test_threadStart failing sporadically on Ubuntu 14.04 #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions TestFoundation/TestThread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ class TestThread : XCTestCase {

func test_threadStart() {
let condition = NSCondition()
condition.lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this end up locking on the condition twice? Is that supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first lock happens in the parent thread - it acquires the lock.
The second lock happens in the newly created lock - it blocks waiting to acquire it.
When the parent thread calls condition.wait() the lock is unlocked and then the 2nd thread acquires it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes - the change makes sense in that regard.


let thread = Thread() {
condition.lock()
condition.broadcast()
condition.unlock()
}
thread.start()

condition.lock()

let ok = condition.wait(until: Date(timeIntervalSinceNow: 10))
condition.unlock()
XCTAssertTrue(ok, "NSCondition wait timed out")
Expand Down Expand Up @@ -95,6 +96,8 @@ class TestThread : XCTestCase {
XCTAssertTrue(c.isEqual(t))

let condition = NSCondition()
condition.lock()

let thread = Thread() {
condition.lock()
XCTAssertFalse(Thread.isMainThread)
Expand All @@ -104,7 +107,6 @@ class TestThread : XCTestCase {
}
thread.start()

condition.lock()
let ok = condition.wait(until: Date(timeIntervalSinceNow: 10))
condition.unlock()
XCTAssertTrue(ok, "NSCondition wait timed out")
Expand Down