sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
main.cpp
1
#include <cstdio>
2
#include <cstring>
3
4
extern
"C"
{
5
#include <
kernel.h
>
6
}
7
8
#include <atomic>
9
#include <thread>
10
11
extern
"C"
int
kputs(
char
*s);
12
13
/* A program must never return from main on the rig: that reboots the console. */
14
static
int
rig_failed;
15
static
int
rig_kputs(
char
*s) {
16
if
(strstr(s,
": FAIL"
)) rig_failed = 1;
17
return
kputs(s);
18
}
19
#define kputs rig_kputs
20
21
static
std::atomic<int> destroyed{0};
22
23
struct
Tracked {
24
int
value;
25
explicit
Tracked(
int
v) : value(v) {}
26
~Tracked() { destroyed++; }
27
};
28
29
thread_local
int
counter = 100;
30
thread_local
Tracked
tracked{7};
31
32
static
std::atomic<int> sums[2];
33
34
static
void
worker(
int
index) {
35
counter += index + 1;
36
tracked.value += index;
37
sums[index] = counter * 1000 + tracked.value;
38
}
39
40
static
int
test_main() {
41
counter = 5;
42
std::thread a(worker, 0);
43
std::thread b(worker, 1);
44
a.join();
45
b.join();
46
47
bool
ok = counter == 5 && tracked.value == 7;
48
ok = ok && sums[0] == 101 * 1000 + 7 && sums[1] == 102 * 1000 + 8;
49
ok = ok && destroyed == 2;
50
kputs(ok ?
const_cast<
char
*
>
(
"cxx-thread-local: PASS\n"
) :
const_cast<
char
*
>
(
"cxx-thread-local: FAIL\n"
));
51
return
0;
52
}
53
54
int
main() {
55
int
result = test_main();
56
printf(
"[ps2rig] exit=%d\n"
, (result || rig_failed) ? 1 : 0);
57
SleepThread();
58
return
0;
59
}
kernel.h
Tracked
Definition
main.cpp:23
tests
cxx-thread-local
src
main.cpp
Generated by
1.18.0