mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Store threads with unique_ptr in ListenConnectParallel
The existing implementation uses raw pointers, which means: - Threads are joined at the end of each loop, and the test therefore doesn't actually exercise the syscalls in parallel. - The later call to `Join` is undefined behavior. PiperOrigin-RevId: 478845631
This commit is contained in:
@@ -1111,9 +1111,11 @@ TEST_P(SimpleTcpSocketTest, ListenConnectParallel) {
|
||||
});
|
||||
|
||||
// Initiate connects in a separate thread.
|
||||
std::vector<ScopedThread*> threads;
|
||||
std::vector<std::unique_ptr<ScopedThread>> threads;
|
||||
threads.reserve(num_threads);
|
||||
for (int i = 0; i < num_threads; i++) {
|
||||
ScopedThread t([&addr, &addrlen, family]() {
|
||||
threads.push_back(std::make_unique<ScopedThread>([&addr, &addrlen,
|
||||
family]() {
|
||||
const FileDescriptor c = ASSERT_NO_ERRNO_AND_VALUE(
|
||||
Socket(family, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP));
|
||||
|
||||
@@ -1126,11 +1128,7 @@ TEST_P(SimpleTcpSocketTest, ListenConnectParallel) {
|
||||
struct pollfd poll_fd = {c.get(), POLLERR | POLLOUT, 0};
|
||||
EXPECT_THAT(RetryEINTR(poll)(&poll_fd, 1, 1000),
|
||||
SyscallSucceedsWithValue(1));
|
||||
});
|
||||
threads.push_back(&t);
|
||||
}
|
||||
for (auto t : threads) {
|
||||
t->Join();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user