Skip to content

Hellzy/cpp-threadpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPP Threadpool

A simple threadpool implementation to abstract std::thread management. Ongoing.

Requirements

  • CMake
  • pthread
  • C++17 capable compiler

Building

mkdir build
cd build
cmake ..
make

Linking to the library

LDLIBS += -ltpool
LD_LIBRARY_PATH=path/to/libtpool.so/folder

Examples

Basic example

Non-void return type

#include <cassert>

#include "threadpool.hh"

static int sum(int a, int b)
{
    return a + b;
}

int main()
{

    ThreadPool t;
    int a = 10;
    int b = 22;

    auto fut = t.submit(sum, a, b);
    assert(fut.get() == sum(a, b));

    return 0;
}

void return type

#include <iostream>
#include <string>

#include "threadpool.hh"

static void disp(const std::string& str)
{
    std::cout << str << '\n';
}

int main()
{
    ThreadPool t;
    t.submit(disp, "Hello World!");

    return 0;
}

What's next?

  • Working on introducing scheduled tasks
  • Maybe try to introduce something like sequential streams mechanics

About

A basic threadpool implementation for C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published