diff --git a/repos/mml/src/app/posix_playground/main.cc b/repos/mml/src/app/posix_playground/main.cc index 6db6c59fec..cf32a81126 100644 --- a/repos/mml/src/app/posix_playground/main.cc +++ b/repos/mml/src/app/posix_playground/main.cc @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include namespace Posix_playground { class Chrono_thread; @@ -44,30 +47,32 @@ int main(void) { std::cout << "Let's start some threads" << std::endl; - std::vector thread_objs(5); + std::unique_ptr> thread_objs = std::make_unique>(); std::vector thread_list(4); std::cout << "Let's use aligned memory for threads objects." << std::endl; for (int i = 0; i < 3; i++) { - Posix_playground::Chrono_thread *thread_obj; - if(posix_memalign((void**)(&thread_obj), 64, sizeof(Posix_playground::Chrono_thread))) { + Posix_playground::Chrono_thread *thread_obj = nullptr; + // std::unique_ptr thread_obj; + if((posix_memalign((void**)&thread_obj, 64, sizeof(Posix_playground::Chrono_thread)))) { std::cerr << "Could not allocate thread object " << i << std::endl; continue; } std::cout << "Thread object " << (i + 1) << " is at address " << (void *)(thread_obj) << std::endl; - thread_objs[i] = new (thread_obj) Posix_playground::Chrono_thread((std::uint16_t)(i+1)); + thread_objs.get()->emplace_back(new (thread_obj) Posix_playground::Chrono_thread((std::uint16_t)(i+1))); - auto thread = new std::thread([thread_objs, i] - { thread_objs[i]->execute(); }); + auto thread = new std::thread([&thread_objs, i] + { (thread_objs.get()->at(i))->execute(); }); thread_list[i] = thread; } for (auto thread : thread_list) { thread->join(); } - + + while(true); return 0;