在C中获取并设置线程属性的堆栈大小
要获取并设置C中线程属性的堆栈大小,我们使用以下线程属性:
pthread_attr_getstacksize()
用于获取线程堆栈大小。stacksize属性给出分配给线程堆栈的最小堆栈大小。如果运行成功,则给出0,否则给出任何值。
它有两个参数-
pthread_attr_getstacksize(pthread_attr_t*attr,size_t*stacksize)
第一个是pthread属性。
第二个给出线程属性的大小。
pthread_attr_setstacksize()
用于设置新线程的堆栈大小。stacksize属性给出分配给线程堆栈的最小堆栈大小。如果运行成功,则给出0,否则给出任何值。
它有两个参数-
pthread_attr_setstacksize(pthread_attr_t*attr,size_t*stacksize)
第一个是pthread属性。
第二个用于给出新堆栈的大小(以字节为单位)。
算法
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\n", stacksize);
pthread_attr_setstacksize(&a, 67626);
pthread_attr_getstacksize(&a, &stacksize);
printf("New stack size= %d\n", stacksize);
return 0;
}输出结果
Current stack size = 50 New stack size= 67626
热门推荐
10 节日祝福语简短个性文案
11 虎年孩子说简短祝福语
12 送礼祝福语简短有深意
13 作文老师寄语简短祝福语
14 立春祝福语简短微信
15 女孩自己生日祝福语简短
16 同事贺卡祝福语简短冬日
17 简短生日祝福语女朋友
18 三八祝福语简短文案