diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-08 10:51:08 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-08 10:51:08 +0100 |
| commit | 00cea265f341a9f62f7183dc3d45dadfac1bcd97 (patch) | |
| tree | 26315ad1ed9ff551649154056a14980609c7c744 | |
| parent | 97d846f41e2bccf7957983c03d1fe9867b789efb (diff) | |
[CHORE] Update example for allocator_op.update-allocator-op-example
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | example/allocator_op_example/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | example/allocator_op_example/example.cpp | 19 | ||||
| -rw-r--r-- | include/ocl/allocator_op.hpp | 4 |
3 files changed, 24 insertions, 6 deletions
diff --git a/example/allocator_op_example/CMakeLists.txt b/example/allocator_op_example/CMakeLists.txt index c7b3d6d..544ee2f 100644 --- a/example/allocator_op_example/CMakeLists.txt +++ b/example/allocator_op_example/CMakeLists.txt @@ -12,4 +12,9 @@ add_executable(AllocatorExample example.cpp) set_property(TARGET AllocatorExample PROPERTY CXX_STANDARD 20) target_include_directories(AllocatorExample PUBLIC ../../include/) -target_link_libraries(AllocatorExample PRIVATE Boost) + +if (NOT DEFINED LINUX) + target_link_libraries(AllocatorExample PRIVATE Boost) +endif() + + diff --git a/example/allocator_op_example/example.cpp b/example/allocator_op_example/example.cpp index 665df0b..ca192ff 100644 --- a/example/allocator_op_example/example.cpp +++ b/example/allocator_op_example/example.cpp @@ -5,15 +5,28 @@ #include <ocl/print.hpp> #include <ocl/allocator_op.hpp> +#include <coroutine> +#include <future> /// \brief Allocation of ints example. -int main() +int task() { ocl::allocator<int> int_alloc; auto foo = int_alloc.construct_array<1>(); - *foo = 67; - ocl::io::print(*foo); + *foo = 109000; + ocl::io::println(*foo); return EXIT_SUCCESS; } + +int main() +{ + auto ret = std::async(std::launch::deferred, task); + auto ret2 = std::async(std::launch::deferred, task); + auto ret3 = std::async(std::launch::deferred, task); + + ret.get(); + ret2.get(); + ret3.get(); +} diff --git a/include/ocl/allocator_op.hpp b/include/ocl/allocator_op.hpp index 43bc80b..84a949a 100644 --- a/include/ocl/allocator_op.hpp +++ b/include/ocl/allocator_op.hpp @@ -75,7 +75,7 @@ namespace ocl template <typename... var_type> auto construct_var(var_type&&... args) { - allocator_new alloc; + static allocator_new alloc; typename allocator_new::lock_type lt{alloc.m_}; return std::shared_ptr<ret_type>(alloc.template var_alloc<var_type...>(std::forward<var_type...>(args)...), allocator_delete{}); } @@ -83,7 +83,7 @@ namespace ocl template <std::size_t N> auto construct_array() { - allocator_new alloc; + static allocator_new alloc; typename allocator_new::lock_type lt{alloc.m_}; return std::shared_ptr<ret_type>(alloc.template array_alloc<N>(), allocator_delete{}); } |
