Skip to content

Commit

Permalink
Merge pull request #218 from Inari-Whitebear/master
Browse files Browse the repository at this point in the history
Change language in test case to more accurately describe peer relationship of threads
  • Loading branch information
jckarter committed Dec 6, 2015
2 parents b6d40e6 + 199ac15 commit a42ce37
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions validation-test/stdlib/StringSlicesConcurrentAppend.swift
Expand Up @@ -25,13 +25,13 @@ extension String {
// different non-shared strings that point to the same shared buffer.

enum ThreadID {
case Leader
case Follower
case Primary
case Secondary
}

var barrierVar: UnsafeMutablePointer<_stdlib_pthread_barrier_t> = nil
var sharedString: String = ""
var followerString: String = ""
var secondaryString: String = ""

func barrier() {
var ret = _stdlib_pthread_barrier_wait(barrierVar)
Expand All @@ -41,7 +41,7 @@ func barrier() {
func sliceConcurrentAppendThread(tid: ThreadID) {
for i in 0..<100 {
barrier()
if tid == .Leader {
if tid == .Primary {
// Get a fresh buffer.
sharedString = ""
sharedString.appendContentsOf("abc")
Expand All @@ -57,7 +57,7 @@ func sliceConcurrentAppendThread(tid: ThreadID) {
barrier()

// Append to the private string.
if tid == .Leader {
if tid == .Primary {
privateString.appendContentsOf("def")
} else {
privateString.appendContentsOf("ghi")
Expand All @@ -66,22 +66,22 @@ func sliceConcurrentAppendThread(tid: ThreadID) {
barrier()

// Verify that contents look good.
if tid == .Leader {
if tid == .Primary {
expectEqual("abcdef", privateString)
} else {
expectEqual("abcghi", privateString)
}
expectEqual("abc", sharedString)

// Verify that only one thread took ownership of the buffer.
if tid == .Follower {
followerString = privateString
if tid == .Secondary {
secondaryString = privateString
}
barrier()
if tid == .Leader {
if tid == .Primary {
expectTrue(
(privateString.bufferID == sharedString.bufferID) !=
(followerString.bufferID == sharedString.bufferID))
(secondaryString.bufferID == sharedString.bufferID))
}
}
}
Expand All @@ -93,9 +93,9 @@ StringTestSuite.test("SliceConcurrentAppend") {
expectEqual(0, ret)

let (createRet1, tid1) = _stdlib_pthread_create_block(
nil, sliceConcurrentAppendThread, .Leader)
nil, sliceConcurrentAppendThread, .Primary)
let (createRet2, tid2) = _stdlib_pthread_create_block(
nil, sliceConcurrentAppendThread, .Follower)
nil, sliceConcurrentAppendThread, .Secondary)

expectEqual(0, createRet1)
expectEqual(0, createRet2)
Expand Down

0 comments on commit a42ce37

Please sign in to comment.