Skip to content

task_fence

Alairion edited this page May 8, 2021 · 2 revisions

nes::task_fence

Defined in header <nes/thread_pool.hpp>

class task_fence;

Description

nes::task_fence

Public Member functions

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

Example

main.cpp

#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;
}

Output

Launching first the work
Work started
Fence signaled, second task started
Clone this wiki locally