Windows下pthread_attr_getstacksize的大小

参考前辈的博客中提到Linux下线程默认大小是8192KB,便想查看Windows下的值,意外的打印出0,不一致,便启动搜索引擎,发现大部分博客均为提到Windows场景,遂有此文。

在POSIX Reference中,找到了pthread_attr_getstacksize()文档,其中提到以下内容:

Pthreads-w32 defines _POSIX_THREAD_ATTR_STACKSIZE in pthread.h to indicate that these routines are implemented and may be used to set or get the stack size.

Default value: 0 (in Pthreads-w32 a value of 0 means the stack will grow as required)

文档连接在此

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>//线程操作所需头文件

int main(void)
{
	size_t stack_size = 0; //堆栈大小变量
	pthread_attr_t attr; //线程属性结构体变量

	//初始化线程属性
	int ret = pthread_attr_init(&attr);
	if(ret != 0)
	{
		perror("pthread_attr_init");
		return -1;
	}

	//获取当前的线程栈大小
    ret = pthread_attr_getstacksize(&attr, &stack_size);
    if(ret != 0)
	{
		perror("pthread_attr_getstacksize");
		return -1;
	}

	//打印堆栈值
	printf("stack_size = %dB, %dk\n", stack_size, stack_size/1024);

    return 0;
}

版权声明:本文为qq_43732324原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。