Add minimal Genode::Thread example

This commit is contained in:
2019-03-26 17:45:46 +01:00
parent dfea92c1cf
commit 416eb33299
3 changed files with 69 additions and 0 deletions

26
run/threads.run Normal file
View File

@@ -0,0 +1,26 @@
build { core init app/threads }
create_boot_directory
install_config {
<config>
<parent-provides>
<service name="LOG"/>
<service name="PD"/>
<service name="CPU"/>
<service name="ROM"/>
</parent-provides>
<default-route>
<any-service><parent/><any-child/></any-service>
</default-route>
<default caps="50"/>
<start name="threads">
<resource name="RAM" quantum="1M"/>
</start>
</config>}
build_boot_image { core ld.lib.so init threads }
append qemu_args " -nographic -smp 4 "
run_genode_until forever

40
src/app/threads/main.cc Normal file
View File

@@ -0,0 +1,40 @@
#include <base/component.h>
#include <base/log.h>
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);
}

View File

@@ -0,0 +1,3 @@
TARGET = threads
SRC_CC = main.cc
LIBS = base