From 5087d28b8ad629faa0575f76a60a6247f2f8bc71 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 9 Aug 2015 14:24:24 +0200 Subject: [PATCH] add thread demo --- hermit/newlib/examples/Makefile | 15 +++++++++++---- hermit/newlib/examples/thr_hello.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 hermit/newlib/examples/thr_hello.c diff --git a/hermit/newlib/examples/Makefile b/hermit/newlib/examples/Makefile index c07dd35fd..a576b73a7 100644 --- a/hermit/newlib/examples/Makefile +++ b/hermit/newlib/examples/Makefile @@ -1,7 +1,7 @@ ARCH = x86 TARGET=x86_64-hermit MAKE = make -STRIP_DEBUG = --strip-debug +override STRIP_DEBUG = --strip-unneeded --strip-debug KEEP_DEBUG = --only-keep-debug # Set your own cross compiler tool chain prefix here @@ -37,7 +37,7 @@ endif default: all -all: hello jacobi stream +all: hello jacobi stream thr_hello stream: stream.o @echo [LD] $@ @@ -60,13 +60,20 @@ jacobi: jacobi.o $Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@ $Qchmod a-x $@.sym +thr_hello: thr_hello.o + @echo [LD] $@ + $Q$(CC_FOR_TARGET) $(LDFLAGS) $(CFLAGS) -o $@ $< -lpthread + $Q$(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $@ $@.sym + $Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@ + $Qchmod a-x $@.sym + clean: @echo Cleaning examples - $Q$(RM) hello jacobi *.sym *.o *~ + $Q$(RM) hello jacobi stream thr_hello *.sym *.o *~ veryclean: @echo Propper cleaning examples - $Q$(RM) hello jacobi stream *.sym *.o *~ + $Q$(RM) hello jacobi stream thr_hello *.sym *.o *~ depend: $Q$(CC_FOR_TARGET) -MM $(CFLAGS) *.c > Makefile.dep diff --git a/hermit/newlib/examples/thr_hello.c b/hermit/newlib/examples/thr_hello.c new file mode 100644 index 000000000..dfc1c47fe --- /dev/null +++ b/hermit/newlib/examples/thr_hello.c @@ -0,0 +1,30 @@ +#include +#include + +#define MAX_THREADS 2 + +void* thread_func(void* arg) +{ + int id = *((int*) arg); + + printf("Hello Thread!!! id = %d\n", id); + + return 0; +} + +int main(int argc, char** argv) +{ + pthread_t threads[MAX_THREADS]; + int i, param[MAX_THREADS]; + + for(i=0; i