Skip to content

Commit 1670e0a

Browse files
committed
Fix linking c++
1 parent 84c23bb commit 1670e0a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
// RUN: %clangxx_tsan %s -fsanitize=thread -o %t
1+
// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -fsanitize=thread -o %t
22
// RUN: %run %t 128
33
// RUN: not %run %t 129
44

55
#include <mutex>
6+
#include <vector>
67
#include <string>
78

89
int main(int argc, char *argv[]) {
9-
int num_of_mtx = std::stoi(argv[1]);
10+
int num_of_mtx = std::atoi(argv[1]);
1011

11-
std::mutex *mutexes = new std::mutex[num_of_mtx];
12+
std::vector<std::mutex> mutexes(num_of_mtx);
1213

13-
for (int i = 0; i < num_of_mtx; i++) {
14-
mutexes[i].lock();
14+
for (auto& mu : mutexes) {
15+
mu.lock();
1516
}
16-
for (int i = 0; i < num_of_mtx; i++) {
17-
mutexes[i].unlock();
17+
for (auto& mu : mutexes) {
18+
mu.unlock();
1819
}
1920

20-
delete[] mutexes;
2121
return 0;
2222
}

0 commit comments

Comments
 (0)