aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-10 22:09:47 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-10 22:09:47 +0100
commite10f9802088722e85fd4f2f9cb006d2bdca37d3c (patch)
tree2551f776000f48fbbb0fe8819a661982207e0b35
parent7d0eb550338af7301bc45e2f003812ee487f2d8c (diff)
Add atexit
-rw-r--r--c/atexit/.gitignore1
-rw-r--r--c/atexit/Makefile8
-rw-r--r--c/atexit/main.c33
3 files changed, 42 insertions, 0 deletions
diff --git a/c/atexit/.gitignore b/c/atexit/.gitignore
new file mode 100644
index 0000000..e4608d8
--- /dev/null
+++ b/c/atexit/.gitignore
@@ -0,0 +1 @@
+atexit
diff --git a/c/atexit/Makefile b/c/atexit/Makefile
new file mode 100644
index 0000000..ffcb7ba
--- /dev/null
+++ b/c/atexit/Makefile
@@ -0,0 +1,8 @@
+include ../base.mk
+
+all: atexit
+atexit: main.c
+ $(CC) $(CFLAGS) -lpthread -o $@ $<
+
+clean:
+ rm -f atexit
diff --git a/c/atexit/main.c b/c/atexit/main.c
new file mode 100644
index 0000000..1729edf
--- /dev/null
+++ b/c/atexit/main.c
@@ -0,0 +1,33 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static void *loop(void *);
+static void handler(void);
+
+int
+main(void)
+{
+ pthread_t t;
+
+ atexit(handler);
+ pthread_create(&t, NULL, loop, NULL);
+ sleep(1);
+ return EXIT_SUCCESS;
+}
+
+void *
+loop(void *_)
+{
+ (void)_;
+ for (;;)
+ ;
+ return NULL;
+}
+
+void
+handler(void)
+{
+ puts("hello, world!");
+}