From e10f9802088722e85fd4f2f9cb006d2bdca37d3c Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 10 Dec 2023 22:09:47 +0100 Subject: Add atexit --- c/atexit/.gitignore | 1 + c/atexit/Makefile | 8 ++++++++ c/atexit/main.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 c/atexit/.gitignore create mode 100644 c/atexit/Makefile create mode 100644 c/atexit/main.c 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 +#include +#include +#include + +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!"); +} -- cgit v1.2.3