Skip to content

fq0222/CppThreadPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CppThreadPool

Linux 平台线程池

示例

/*
 *    ___          ___
 *  /'___\       /'___\
 * /\ \__/   __ /\ \__/  __  __  __
 * \ \ ,__\/'__`\ \ ,__\/\ \/\ \/\ \
 *  \ \ \_/\ \L\ \ \ \_/\ \ \_/ \_/ \
 *   \ \_\\ \___, \ \_\  \ \___x___/'
 *    \/_/ \/___/\ \/_/   \/__//__/
 *              \ \_\
 *               \/_/
 */

#include <iostream>
#include <cstdio>
#include <chrono>
#include <thread>
#include "Executor.h"
#include "ExecutorService.h"
#include "Task.h"

using namespace fqfw;

class TestTask : public Task
{
public:
    TestTask() {}
    virtual ~TestTask() {}

    virtual void run(std::thread::id tid) {
        std::this_thread::sleep_for(std::chrono::seconds(2));
        printf("Tid: %ld TestTask run\n", tid);
    }
};


int main(int argc, char *argv[])
{
    printf("Hello FQFW Thread Pool\n");
    std::shared_ptr<ExecutorService> executor = Executor::newFixedThreadPool(15);


    for (int i = 0; i < 50; ++i) {
        std::shared_ptr<Task> task = std::shared_ptr<Task>(new TestTask());
        executor->post(task);
    }


    std::this_thread::sleep_for(std::chrono::seconds(10));

    executor->shutdown();

    return 0;
}

About

Linux 平台线程池

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors