blob: 3003fa1635bfba93893ce66042e329ac415e8f36 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include "tls.h"
#include "thread.h"
#include <library/cpp/testing/unittest/registar.h>
Y_UNIT_TEST_SUITE(TTestTLS) {
struct X {
inline X()
: V(0)
{
}
inline void Do() {
++TlsRef(V);
}
inline int Get() {
return TlsRef(V);
}
Y_THREAD(int)
V;
};
Y_UNIT_TEST(TestHugeSetup) {
TArrayHolder<X> x(new X[100000]);
struct TThr: public ISimpleThread {
inline TThr(X* ptr)
: P(ptr)
{
}
void* ThreadProc() noexcept override {
for (size_t i = 0; i < 100000; ++i) {
P[i].Do();
}
return nullptr;
}
X* P;
};
TThr thr1(x.Get());
TThr thr2(x.Get());
thr1.Start();
thr2.Start();
thr1.Join();
thr2.Join();
for (size_t i = 0; i < 100000; ++i) {
UNIT_ASSERT_VALUES_EQUAL(x.Get()[i].Get(), 0);
}
}
}
|