要在C中获取和设置线程属性的堆栈大小,我们使用以下线程属性:
用于获取线程堆栈大小。stacksize属性给出了分配给线程堆栈的最小堆栈大小。如果成功运行,则返回0,否则返回任何值。
它接受两个参数:
pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)
用于设置新的线程堆栈大小。stacksize属性给出了分配给线程堆栈的最小堆栈大小。如果成功运行,则返回0,否则返回任何值。
它接受两个参数:
pthread_attr_setstacksize(pthread_attr_t *attr, size_t *stacksize)
Begin Declare stack size and declare pthread attribute a. Gets the current stacksize by pthread_attr_getstacksize() and print it. Set the new stack size by pthread_attr_setstacksize() and get the stack size pthread_attr_getstacksize() and print it. End
#include <stdio.h> #include <stdlib.h> #include <pthread.h> int main() { size_t stacksize; pthread_attr_t a; pthread_attr_getstacksize(&a, &stacksize); printf("Current stack size = %d</p><p>", stacksize); pthread_attr_setstacksize(&a, 67626); pthread_attr_getstacksize(&a, &stacksize); printf("New stack size= %d</p><p>", stacksize); return 0; }
Current stack size = 50 New stack size= 67626
以上是获取和设置C语言中线程属性的堆栈大小的详细内容。更多信息请关注PHP中文网其他相关文章!