-
Notifications
You must be signed in to change notification settings - Fork 7
task_fence
Alairion edited this page May 8, 2021
·
2 revisions
Defined in header <nes/thread_pool.hpp>
class task_fence;
nes::task_fence
Function | Description |
---|---|
task_fence |
Creates a new task fence |
~task_fence |
Destroys the task fence |
operator= |
Assigns a task fence |
signal |
Signals the fence, allowing the task list to pass through it |
#include <iostream>
#include <nes/thread_pool.hpp>
int main()
{
nes::task_builder builder{};
builder.dispatch(42, 12, 3, [](std::uint32_t x, std::uint32_t y, std::uint32_t z)
{
//Do something
});
nes::task_fence fence{builder.fence()}; // Will blocks before the execute until we signal it
builder.execute([]()
{
//Do something
});
nes::thread_pool thread_pool{};
std::cout << "Launching first the work" << std::endl;
thread_pool.push(builder.build());
std::cout << "Work started" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds{500});
fence.signal();
std::cout << "Fence signaled, second task started" << std::endl;
}
Launching first the work
Work started
Fence signaled, second task started