处理字符串的最佳线程数
C++ - Optimal number of threads for processing string
我有一个长度N的std::string,我想使用线程将长度K的所有子字符串插入到std::set容器中。我应该使用多少std::thread或pthread_t对象?
考虑N = 500,000, K = 3
使用ThreadPool。
它使用起来很简单,你只需要include "ThreadPool.h"
,你可以根据可用的内核数量设置最大线程数。您的代码应该包含以下代码段:
int max_threads = std::thread::hardware_concurrency();
ThreadPool pool(max_threads);
auto result = pool.enqueue(func,params);
这里func
是要调用的函数,params
是参数,返回值将存储在result
中
相关文章:
- 将线程中的数据存储到全局容器的最佳方法?
- 最佳做法是从另一个线程访问 qml 中的Q_PROPERTY
- 处理影响跨不同线程共享对象的定时回调的最佳方法是什么?
- std::使用类成员函数创建线程 - 最佳实践
- 等待线程的最佳方式是什么
- 存储/传递 v8 承诺解析器供以后使用的最佳实践?(结合C++线程)
- 套接字发送(.)线程的最佳数量
- 线程数据封装最佳实践
- 最佳多线程全局变量管理
- 从QTcpSocket上的数据流中连续运行复杂算法的最佳Qt线程解决方案是什么
- 多线程 UI 的最佳方式
- 暂停和恢复线程的最佳解决方案是什么?
- 使用来自不同线程的实时数据更新QTableView的最佳策略
- 从线程更新进度条的最佳方式
- C++/Win32 我在 Windows 2000+ 上启动线程的最佳方式
- 控制对多线程程序中字符串对象的访问的最佳方法
- std::线程管理:用法和最佳实践
- 在多个相互依赖的线程上进行封送处理和等待的算法、模式或最佳实践
- Eclipse CDT 多线程调试不是最佳的 - 如何以独占方式运行线程
- 使用Qt框架减少多线程应用程序中数据库连接的最佳策略