我在Ubuntu 16.04中创建线程并检索数据如下所示
vector<std::future<TestResult>> futureVector;
for(int i = 0; i < number_of_threads; i ++) {
auto future = std::async(
std::launch::async,
&testFunction,
this,
parameter);
futureVector.push_back(move(future));
}
for (int i = 0; i < futureVector.size(); i++)
{
auto result = futureVector[i].get();
}
但它会抛出
描述“资源暂时不可用
的异常
我认为这可能是因为我创建了太多超出操作系统限制的线程。如果任何人都可以提供调试方法,那将非常有用。
编辑:
ulimit的结果-a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 983354
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 983354
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited