From 631477c7b87ae43ab0d55f07e131918064a33c82 Mon Sep 17 00:00:00 2001 From: Nick Brown Date: Tue, 4 Oct 2022 11:46:56 -0700 Subject: [PATCH] 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 --- test/syscalls/linux/tcp_socket.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/syscalls/linux/tcp_socket.cc b/test/syscalls/linux/tcp_socket.cc index 8bdac0d91..5b9a61775 100644 --- a/test/syscalls/linux/tcp_socket.cc +++ b/test/syscalls/linux/tcp_socket.cc @@ -1111,9 +1111,11 @@ TEST_P(SimpleTcpSocketTest, ListenConnectParallel) { }); // Initiate connects in a separate thread. - std::vector threads; + std::vector> threads; + threads.reserve(num_threads); for (int i = 0; i < num_threads; i++) { - ScopedThread t([&addr, &addrlen, family]() { + threads.push_back(std::make_unique([&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(); + })); } }