summaryrefslogtreecommitdiff
path: root/targets/threads.c
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:58:00 -0300
committerGabriel Schneider <[email protected]>2026-11-10 11:58:53 -0300
commit8beab959b633e6641d07aba053a55e6e8e61eb00 (patch)
tree0e5a91c0a00e121fe4094a333438ee90ccc5fdda /targets/threads.c
parent3fdb67c479dcc1ad0f1e51832bc086622692249c (diff)
downloadcomputeranim-8beab959b633e6641d07aba053a55e6e8e61eb00.tar.gz
computeranim-8beab959b633e6641d07aba053a55e6e8e61eb00.zip
targets, test-debugger, bench-debugger
A linked list, a graph search in Zig, the same C under glibc and musl, two threads. The tests drive the debugger over them: breakpoint counts, the lines a step walks (as gdb), a list snapshotted by a hook, a watch's words, the syscalls that tell glibc from musl, threads, attach, and scripted dbg and record sessions. The bench measures steps, stops and memory access from bare ptrace up to a recording. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'targets/threads.c')
-rw-r--r--targets/threads.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/targets/threads.c b/targets/threads.c
new file mode 100644
index 0000000..ab4d80d
--- /dev/null
+++ b/targets/threads.c
@@ -0,0 +1,26 @@
+// Two threads and a mutex: each adds its share to `total`, main joins them
+// and prints it. What clone, futex and a thread's exit look like to a tracer.
+#include <pthread.h>
+#include <stdio.h>
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+long total;
+
+__attribute__((noinline)) static void *work(void *arg) {
+ for (long i = 0; i < 1000; i++) {
+ pthread_mutex_lock(&lock);
+ total += (long)arg;
+ pthread_mutex_unlock(&lock);
+ }
+ return NULL;
+}
+
+int main(void) {
+ pthread_t a, b;
+ pthread_create(&a, NULL, work, (void *)1);
+ pthread_create(&b, NULL, work, (void *)2);
+ pthread_join(a, NULL);
+ pthread_join(b, NULL);
+ printf("total = %ld\n", total);
+ return 0;
+}