-
Notifications
You must be signed in to change notification settings - Fork 10.5k
unittests/runtime: Migrate tests from pthreads to std::thread #14598
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
The head ref may contain hidden characters: "pthreads=\u{1F625}"
Conversation
4801d7f
to
6689703
Compare
CC: @gparker42 |
c21d7ed
to
7c1f63d
Compare
@swift-ci please smoke test |
afd0e45
to
70603fd
Compare
unittests/runtime/Metadata.cpp
Outdated
unsigned numThreads; | ||
unsigned *numThreadsReady; | ||
std::mutex *sharedMutex; | ||
std::condition_variable *start_condition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these fields be references instead of pointers?
unittests/runtime/Metadata.cpp
Outdated
@@ -249,7 +185,7 @@ TEST(Concurrent, ConcurrentList) { | |||
} | |||
|
|||
// Check that the length of the list is correct. | |||
EXPECT_EQ(ListLen, results.size() * numElem); | |||
EXPECT_EQ(ListLen, 0 * numElem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong. Why are we verifying the contents of List and then asserting that List is empty?
Should have said this: The patch is currently in progress, I know that's broken. I'll ping you when its ready to be reviewed. |
ab1a0d7
to
3b948bf
Compare
I think this is the patch I want. I'm testing it locally, but CI will probably go faster @compnerd / @gparker42 could you ask CI to test? @gparker42 I might have changes to fix this, but this is more or less the change I was thinking. Took your references instead of pointer comment into account. |
3f3077e
to
9dacfa2
Compare
b7a846a
to
af0ec97
Compare
unittests/runtime/Metadata.cpp
Outdated
std::vector<T> | ||
RaceTest(std::function<T()> code) | ||
{ | ||
std::vector<T> RaceTest(std::function<T()> code) { | ||
const unsigned threadCount = NumThreads; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure I understand the point of the threadCount
variable. Why not just use NumThreads
everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was in the original implementation, I think it was because pthreads required an unsigned
.
I'll remove it
@swift-ci please test |
Build failed |
Build failed |
@compnerd I removed |
unittests/runtime/Metadata.cpp
Outdated
|
||
// Create all the threads | ||
for (unsigned i = 0; i < NumThreads; i++) { | ||
threads.emplace_back(std::thread(RaceThunk<T>, contexts[i])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This combination of sized constructor and emplace_back()
looks wrong. I think it creates a vector of 2*NumThreads
elements, with the first half being default-initialized and the second half being the desired contents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry! I'm still learning cpp, my bad 😬
How should I update the vector initializer to not fill in default values? I looked at http://en.cppreference.com/w/cpp/container/vector/vector but it doesn't seem easy to have the Allocator
not insert values. Should I switch from emplace_back
ing to assigning to threads[i]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this code simply assigning to threads[i]
should be fine. Or create an empty vector and push_back
or emplace_back
onto it, like the old pthreads code did. Both of these might have performance downsides, but we don't care in this code.
This stackoverflow answer has a good overview of the combinations that work and their performance effects.
https://stackoverflow.com/a/32200517/881456
@gparker42 that was an interesting read. Thank you 😄 |
@swift-ci please test |
Build failed |
Build failed |
Xcode updated @swift-ci please test |
Build failed |
Build failed |
This looks like a legitimate failure, not just an infra issue. Investigating today |
95ab994
to
99056d4
Compare
unittests/runtime/Metadata.cpp
Outdated
std::vector<std::thread> threads; | ||
threads.reserve(NumThreads); | ||
for (unsigned i = 0; i < NumThreads; i++) | ||
threads.emplace_back(std::bind(RaceThunk<T>, contexts[i])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a std::cref
on the contexts[i]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, thank you 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
Build failed |
Build failed |
@gparker42 can you take a look last this? After your review it should be good to merge |
This is required for Windows, which has std::threads, but no pthreads.
This is probably completely broken, working on running the tests locally right now.
If a member could ask @swift-ci to test, that would be much appreciated ❤️