diff --git a/repos/mml/run/posix_playground.run b/repos/mml/run/posix_playground.run new file mode 100644 index 0000000000..59f982391d --- /dev/null +++ b/repos/mml/run/posix_playground.run @@ -0,0 +1,46 @@ +build "core init timer app/posix_playground" +create_boot_directory + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +set boot_modules { + core init timer vfs.lb.so ld.lib.so libc.lib.so libm.lib.so stdcxx.lib.so posix_playground +} + +build_boot_image $boot_modules +append qemu_args "-nographic -m 64" \ No newline at end of file diff --git a/repos/mml/src/app/posix_playground/main.cc b/repos/mml/src/app/posix_playground/main.cc new file mode 100644 index 0000000000..b0b021d419 --- /dev/null +++ b/repos/mml/src/app/posix_playground/main.cc @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include + +namespace Posix_playground { + class Chrono_thread; +} + +class Posix_playground::Chrono_thread { + + private: + std::uint16_t _id; + + public: + Chrono_thread(std::uint16_t id) : _id(id) { } + + void execute() + { + while (true) { + Genode::log("Pong from Thread ", _id); + auto start = std::chrono::steady_clock::now(); + std::this_thread::sleep_for(std::chrono::duration_cast(std::chrono::milliseconds(_id * 1000))); + auto end = std::chrono::steady_clock::now(); + Genode::log("Thread ", _id, " woke up after ", std::chrono::duration_cast(end - start)); + } + } +}; + +int main(void) { + Genode::log("Starting POSIX stdcxx playground"); + + Genode::log("Let's start some threads"); + + std::vector thread_objs(4); + std::vector> thread_list(4); + + for (int i = 0; i < 4; i++) { + Posix_playground::Chrono_thread thread_objs[i] = *new Posix_playground::Chrono_thread(i); + auto thread = std::make_unique([&] + { thread_objs[i].execute(); }); + thread_list.push_back(thread); + thread->join(); + } + + return 0; +} \ No newline at end of file diff --git a/repos/mml/src/app/posix_playground/target.mk b/repos/mml/src/app/posix_playground/target.mk new file mode 100644 index 0000000000..9e589affe7 --- /dev/null +++ b/repos/mml/src/app/posix_playground/target.mk @@ -0,0 +1,5 @@ +TARGET = thread_test +SRC_CC = thread_test.cc +LIBS += base posix libm libc stdcxx +CXXFLAGS += -Wno-error +