File tree Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < snmalloc/snmalloc.h>
2
+ #include < thread>
3
+ #include < vector>
4
+
5
+ snmalloc::CombiningLock cl;
6
+
7
+ std::atomic<bool > run{true };
8
+
9
+ void loop ()
10
+ {
11
+ size_t j = 0 ;
12
+ size_t i = 0 ;
13
+ while (run)
14
+ {
15
+ i++;
16
+ snmalloc::with (cl, [&]() { j++; });
17
+ if (i != j)
18
+ snmalloc::error (" i != j" );
19
+ }
20
+ }
21
+
22
+ int main ()
23
+ {
24
+ std::vector<std::thread> threads;
25
+ for (size_t i = 0 ; i < 8 ; i++)
26
+ {
27
+ threads.emplace_back (std::thread (loop));
28
+ }
29
+
30
+ std::this_thread::sleep_for (std::chrono::seconds (100 ));
31
+ run = false ;
32
+
33
+ for (auto & t : threads)
34
+ {
35
+ t.join ();
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ #include " test/opt.h"
2
+ #include " test/setup.h"
3
+ #include " test/usage.h"
4
+ #include " test/xoroshiro.h"
5
+
6
+ #include < algorithm>
7
+ #include < iostream>
8
+ #include < snmalloc/snmalloc.h>
9
+ #include < thread>
10
+ #include < vector>
11
+
12
+ using namespace snmalloc ;
13
+
14
+ NOINLINE
15
+ void * myrealloc (void * p, size_t size)
16
+ {
17
+ return snmalloc::libc::realloc (p, size);
18
+ }
19
+
20
+ void grow ()
21
+ {
22
+ void * base = nullptr ;
23
+ for (size_t i = 1 ; i < 1000 ; i++)
24
+ {
25
+ base = myrealloc (base, i * 8 );
26
+ }
27
+ snmalloc::libc::free (base);
28
+ }
29
+
30
+ int main ()
31
+ {
32
+ auto start = Aal::tick ();
33
+
34
+ for (size_t i = 0 ; i < 10000 ; i++)
35
+ {
36
+ grow ();
37
+ if (i % 10 == 0 )
38
+ {
39
+ std::cout << " ." << std::flush;
40
+ }
41
+ }
42
+
43
+ auto end = Aal::tick ();
44
+
45
+ std::cout << " Taken: " << end - start << std::endl;
46
+ }
You can’t perform that action at this time.
0 commit comments