sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
main.cpp
1#include <cstdio>
2#include <cstring>
3
4extern "C" {
5#include <kernel.h>
6}
7
8#include <atomic>
9#include <thread>
10
11extern "C" int kputs(char *s);
12
13/* A program must never return from main on the rig: that reboots the console. */
14static int rig_failed;
15static int rig_kputs(char *s) {
16 if (strstr(s, ": FAIL")) rig_failed = 1;
17 return kputs(s);
18}
19#define kputs rig_kputs
20
21static std::atomic<int> destroyed{0};
22
23struct Tracked {
24 int value;
25 explicit Tracked(int v) : value(v) {}
26 ~Tracked() { destroyed++; }
27};
28
29thread_local int counter = 100;
30thread_local Tracked tracked{7};
31
32static std::atomic<int> sums[2];
33
34static void worker(int index) {
35 counter += index + 1;
36 tracked.value += index;
37 sums[index] = counter * 1000 + tracked.value;
38}
39
40static 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
54int main() {
55 int result = test_main();
56 printf("[ps2rig] exit=%d\n", (result || rig_failed) ? 1 : 0);
57 SleepThread();
58 return 0;
59}