diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-14 20:58:23 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-14 20:58:23 +0100 |
commit | 69efa3f630141a74ced338b07d8466a5a0e7557f (patch) | |
tree | fb61f96e27eecceb66952c9c03e783eeeb80284c /Userland | |
parent | c6a8b956432370500df4c19cdccd13806bc18d79 (diff) | |
download | serenity-69efa3f630141a74ced338b07d8466a5a0e7557f.zip |
Kernel+LibPthread: Implement pthread_join()
It's now possible to block until another thread in the same process has
exited. We can also retrieve its exit value, which is whatever value it
passed to pthread_exit(). :^)
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Makefile | 2 | ||||
-rw-r--r-- | Userland/tt.cpp | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/Userland/Makefile b/Userland/Makefile index 3129a738e0..2522e2e23a 100644 --- a/Userland/Makefile +++ b/Userland/Makefile @@ -19,7 +19,7 @@ clean: $(APPS) : % : %.o $(OBJS) @echo "LD $@" - @$(LD) -o $@ $(LDFLAGS) $< -lc -lhtml -lgui -ldraw -laudio -lipc -lthread -lcore -lpcidb -lmarkdown + @$(LD) -o $@ $(LDFLAGS) $< -lc -lhtml -lgui -ldraw -laudio -lipc -lthread -lcore -lpcidb -lmarkdown -lpthread %.o: %.cpp @echo "CXX $<" diff --git a/Userland/tt.cpp b/Userland/tt.cpp new file mode 100644 index 0000000000..e8e56f8c8d --- /dev/null +++ b/Userland/tt.cpp @@ -0,0 +1,25 @@ +#include <pthread.h> +#include <stdio.h> + +int main(int, char**) +{ + printf("Hello from the first thread!\n"); + pthread_t thread_id; + int rc = pthread_create(&thread_id, nullptr, [](void*) -> void* { + printf("Hi there, from the second thread!\n"); + pthread_exit((void*)0xDEADBEEF); + return nullptr; + }, nullptr); + if (rc < 0) { + perror("pthread_create"); + return 1; + } + void* retval; + rc = pthread_join(thread_id, &retval); + if (rc < 0) { + perror("pthread_join"); + return 1; + } + printf("Okay, joined and got retval=%p\n", retval); + return 0; +} |