本文整理汇总了C++中ThreadPool::addTask方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadPool::addTask方法的具体用法?C++ ThreadPool::addTask怎么用?C++ ThreadPool::addTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadPool
的用法示例。
在下文中一共展示了ThreadPool::addTask方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startGame
void Room::startGame(ThreadPool & tp)
{
_game.init(_playerList);
_game.setDelegate(this);
_playing = true;
tp.addTask(new Task(&runGame, &_game));
}
示例2: computeColorsAntialiasing
void Scene::computeColorsAntialiasing(std::function<void(int, int, ColorCRef)> paint, int threadCount, int level) {
upto(threadCount, 1);
downto(threadCount, 4);
std::vector< std::vector <ColorFloat> > m(screen.width, std::vector<ColorFloat> (screen.height, ColorFloat()));
computeColors([paint, &m](int x, int y, ColorCRef c) { m[x][y] = c; paint(x, y, c); }, threadCount);
if (level > 1) {
for (int x = 1; x + 1 < screen.width; x++) {
for (int y = 1; y + 1 < screen.height; y++) {
int badness = 0;
for (int dx : {-1, 1})
for (int dy : {-1, 1})
badness += (m[x][y] - m[x + dx][y + dy]).norm();
if (badness > badnessLimit) {
paint(x, y, Color(255, 0, 0));
}
}
}
int taskCount = 10;
ThreadPool pool;
for (int t = 0; t < taskCount; t++)
pool.addTask([this, &paint, &m, level, t, taskCount]()
{ multiThreadAntialiasePart(paint, m, level, t, taskCount); });
pool.executeAll(threadCount);
}
}
示例3: main
int main() {
ThreadPool<Thread> *threadPool = new ThreadPool<Thread>(3);
for (int i = 0; i < 999; ++ i) {
usleep(1000 * 1000);
cout<<"add Task " << endl;
threadPool->addTask();
}
//threadPool->stop();
delete threadPool;
}
示例4: computeColors
void Scene::computeColors(std::function<void(int, int, ColorCRef)> paint, int threadCount) {
figuresKDTree.init(figures);
upto(threadCount, 1);
downto(threadCount, 4);
int taskCount = 10;
ThreadPool pool;
for (int t = 0; t < taskCount; t++)
pool.addTask([this, &paint, t, taskCount]() { multiThreadComputePartOfColors(paint, t, taskCount); });
pool.executeAll(threadCount);
}
示例5:
void
ThreadPool::addGlobalTask (Task* task)
{
gThreadPool.addTask (task);
}