如何设置stacksize与C ++ 11 std :: thread [英] How to set the stacksize with C++11 std::thread

查看:2691
本文介绍了如何设置stacksize与C ++ 11 std :: thread的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试熟悉C ++ 11中的 std :: thread 库,并且已经到达了一个绊脚石。



最初我来自posix线程背景,并且想知道如何在构建之前设置std ::线程的堆栈大小,因为我似乎找不到任何引用来执行这样的任务。 / p>

使用pthreads设置堆栈大小是这样的:

  void * foo(void * arg); 




pthread_attr_t attribute;
pthread_t thread;

pthread_attr_init(& attribute);
pthread_attr_setstacksize(& attribute,1024);
pthread_create(& thread,& attribute,foo,0);
pthread_join(thread,0);

使用 std :: thread 时,是否有类似的东西?



我一直在使用以下引用:



http://en.cppreference.com/w/cpp/thread

解决方案

< blockquote>

最初我来自一个posix线程背景,并且想知道如何在构建之前设置std ::线程的堆栈大小,因为我似乎找不到任何引用执行这样的任务。


你不能。 std :: thread 不支持,因为 std :: thread 是标准化的,C ++不要求机器甚至有一个堆栈,更不用说一个固定大小的堆栈。



pthreads在它们支持的硬件方面更受限制,并且它假设有一些固定的每个线程的堆栈大小。 (所以你可以配置这个)


I've been trying to familiarize myself with the std::thread library in C++11, and have arrived at a stumbling block.

Initially I come from a posix threads background, and was wondering how does one setup the stack size of the std::thread prior to construction, as I can't seem to find any references to performing such a task.

Using pthreads setting the stack size is done like this:

void* foo(void* arg);
.
.
.
.
pthread_attr_t attribute;
pthread_t thread;

pthread_attr_init(&attribute);
pthread_attr_setstacksize(&attribute,1024);
pthread_create(&thread,&attribute,foo,0);
pthread_join(thread,0);

Is there something similar when using std::thread?

I've been using the following reference:

http://en.cppreference.com/w/cpp/thread

解决方案

Initially I come from a posix threads background, and was wondering how does one setup the stack size of the std::thread prior to construction, as I can't seem to find any references to performing such a task.

You can't. std::thread doesn't support this because std::thread is standardized, and C++ does not require that a machine even has a stack, much less a fixed-size one.

pthreads are more restrictive in terms of the hardware that they support, and it assumes that there is some fixed stack size per thread. (So you can configure this)

这篇关于如何设置stacksize与C ++ 11 std :: thread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆