线程栈默认大小Linux,请问,设置线程栈大小,设置成功,但是不起作用

当前位置:我的异常网» Linux/Unix » 请问,设置线程栈大小,设置成功,但是不起作用

请问,设置线程栈大小,设置成功,但是不起作用

www.myexceptions.net  网友分享于:2013-09-27  浏览:60次

请教,设置线程栈大小,设置成功,但是不起作用

//各位牛哥、牛姐、牛弟、牛妹:

//下面这坨代码,目的是想设置新线程的栈大小,但是不起作用。在下环境Red hat entriprise 6.2, 32位

#include 

#include 

#include 

#include 

#include 

typedef int BOOL;

#define TRUE 1

#define FALSE 0

void *ThOfCreateThread(void *pParam)

{

pthread_attr_t attr;

int nRet = pthread_attr_init(&attr);

if(0 != nRet)

{

printf("!!ThOfCreateThread,1,pthread_attr_init fail,err=%d,%s\n", errno, strerror(errno));

return NULL;

}

size_t tThStackSize = 0;

nRet = ::pthread_attr_getstacksize(&attr, &tThStackSize);

printf("ThOfCreateThread,4,pthread_attr_getstacksize,tThStackSize=%d\n", tThStackSize);

nRet = pthread_attr_destroy(&attr);

if(0 != nRet)

{

printf("!!ThOfCreateThread,7,pthread_attr_destroy fail,err=%d,%s\n", errno, strerror(errno));

}

return NULL;

}

void TestCreateThread()

{

pthread_attr_t attr;

struct sched_param param;

pthread_t m_thread = 0;

size_t m_dwStackSize = 1024 * 1024 * 2;

int nRet = pthread_attr_init(&attr);

if(0 != nRet)

{

printf("!!TestCreateThread,1,pthread_attr_init fail,err=%d,%s\n", errno, strerror(errno));

return ;

}

#if 0

pthread_attr_setschedpolicy(&attr, nPolicy);

pthread_attr_getschedparam(&attr, &param);

param.__sched_priority = nPriority;

pthread_attr_setschedparam(&attr, &param);

#endif

//add by zfq,2013.09.17,begin

if(0 != m_dwStackSize && 10240 

{

int nRet = 0;

size_t tThStackSize = 0;

nRet = ::pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);//设置为非分离线程

if( 0 != nRet)

{

printf("!!TestCreateThread,2,setdetachstate fail,err=%d,%s\n", errno, strerror(errno));

}

nRet = ::pthread_attr_getstacksize(&attr, &tThStackSize);

nRet = ::pthread_attr_setstacksize(&attr, m_dwStackSize);

if( 0 != nRet)

{

printf("!!TestCreateThread,3,setstacksize fail,err=%d,%s\n", errno, strerror(errno));

}

//======test,begin

#if 0

size_t tThStackSize = 0;

nRet = ::pthread_attr_getstacksize(&attr, &tThStackSize);

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值