From 416eb3329994d85d1adebc3a2842a4cffafdcb44 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Tue, 26 Mar 2019 17:45:46 +0100 Subject: [PATCH] Add minimal Genode::Thread example --- run/threads.run | 26 +++++++++++++++++++++++++ src/app/threads/main.cc | 40 +++++++++++++++++++++++++++++++++++++++ src/app/threads/target.mk | 3 +++ 3 files changed, 69 insertions(+) create mode 100644 run/threads.run create mode 100644 src/app/threads/main.cc create mode 100644 src/app/threads/target.mk diff --git a/run/threads.run b/run/threads.run new file mode 100644 index 0000000..c50e5da --- /dev/null +++ b/run/threads.run @@ -0,0 +1,26 @@ +build { core init app/threads } + +create_boot_directory + +install_config { + + + + + + + + + + + + + + + } + +build_boot_image { core ld.lib.so init threads } + +append qemu_args " -nographic -smp 4 " + +run_genode_until forever \ No newline at end of file diff --git a/src/app/threads/main.cc b/src/app/threads/main.cc new file mode 100644 index 0000000..0e0940b --- /dev/null +++ b/src/app/threads/main.cc @@ -0,0 +1,40 @@ +#include +#include + +Genode::size_t Component::stack_size() { return 32 * 1024; } + +namespace Threads { + struct Main; + struct MyThread; +} + +struct Threads::MyThread : Genode::Thread { + void entry() { + for(int i = 0; i<10000; i++) { + Genode::log("i=", i); + } + }; + + MyThread(Genode::Env &env, Genode::String<64> name) : Genode::Thread(env, + Name(name), + 4 * 1024) + { + start(); + }; + ~MyThread() { }; +}; + +struct Threads::Main { + Genode::Env &_env; + + Main(Genode::Env &env) : _env(env) { + Genode::log("Hello World from Threads::Main!"); + + static Threads::MyThread t1(_env, Genode::String<64>("thread_1")); + static Threads::MyThread t2(_env, Genode::String<64>("thread_2")); + } +}; + +void Component::construct(Genode::Env &env) { + static Threads::Main main(env); +} \ No newline at end of file diff --git a/src/app/threads/target.mk b/src/app/threads/target.mk new file mode 100644 index 0000000..0eb6afb --- /dev/null +++ b/src/app/threads/target.mk @@ -0,0 +1,3 @@ +TARGET = threads +SRC_CC = main.cc +LIBS = base \ No newline at end of file