Skip to content

yulangz/cpp_thread_pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A tiny C++ thread pool

A tiny C++ thread pool using producer consumer model.

Example

//
// Created by wanghaitao on 2021/2/20.
//

#include <iostream>
#include <thread>
#include "thread_pool.hpp"


const int Work_Range = 200000;

bool count[Work_Range];


void process(int i) {
    count[i] = true;
    std::this_thread::sleep_for(std::chrono::seconds(1));
}


int main() {
    {
        yulan::ThreadPool<5, 20> pool;

        for (int i = 0; i < Work_Range; ++i) {
            pool.add_task(yulan::make_task(process, i));
        }
    }
    for (int i = 0; i < Work_Range; ++i) {
        if (!count[i]) {
            std::cout << i << "error" << std::endl;
        }
    }
    std::cout << "ok" << std::endl;
    return 0;
}

About

a tiny c++ thread pool

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages