File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
- // RUN: %clangxx_tsan %s -fsanitize=thread -o %t
1
+ // RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -fsanitize=thread -o %t
2
2
// RUN: %run %t 128
3
3
// RUN: not %run %t 129
4
4
5
5
#include < mutex>
6
+ #include < vector>
6
7
#include < string>
7
8
8
9
int main (int argc, char *argv[]) {
9
- int num_of_mtx = std::stoi (argv[1 ]);
10
+ int num_of_mtx = std::atoi (argv[1 ]);
10
11
11
- std::mutex *mutexes = new std::mutex[ num_of_mtx] ;
12
+ std::vector< std::mutex> mutexes ( num_of_mtx) ;
12
13
13
- for (int i = 0 ; i < num_of_mtx; i++ ) {
14
- mutexes[i] .lock ();
14
+ for (auto & mu : mutexes ) {
15
+ mu .lock ();
15
16
}
16
- for (int i = 0 ; i < num_of_mtx; i++ ) {
17
- mutexes[i] .unlock ();
17
+ for (auto & mu : mutexes ) {
18
+ mu .unlock ();
18
19
}
19
20
20
- delete[] mutexes;
21
21
return 0 ;
22
22
}
You can’t perform that action at this time.
0 commit comments