博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
posix多线程有感--线程高级编程(线程属性函数总结)(代码)
阅读量:5318 次
发布时间:2019-06-14

本文共 2085 字,大约阅读时间需要 6 分钟。

/* * thread_attr.c * * Create a thread using a non-default attributes object, * thread_attr. The thread reports its existence, and exits. The * attributes object specifies that the thread be created * detached, and, if the stacksize attribute is supported, the * thread is given a stacksize twice the minimum value. */#include 
#include
#include "errors.h"/* * Thread start routine that reports it ran, and then exits. */void *thread_routine (void *arg){ printf ("The thread is here\n"); return NULL;}int main (int argc, char *argv[]){ pthread_t thread_id; pthread_attr_t thread_attr; struct sched_param thread_param; size_t stack_size; int status; status = pthread_attr_init (&thread_attr); if (status != 0) err_abort (status, "Create attr"); /* * Create a detached thread. */ status = pthread_attr_setdetachstate ( &thread_attr, PTHREAD_CREATE_DETACHED); if (status != 0) err_abort (status, "Set detach");#ifdef _POSIX_THREAD_ATTR_STACKSIZE /* * If supported, determine the default stack size and report * it, and then select a stack size for the new thread. * * Note that the standard does not specify the default stack * size, and the default value in an attributes object need * not be the size that will actually be used. Solaris 2.5 * uses a value of 0 to indicate the default. */ status = pthread_attr_getstacksize (&thread_attr, &stack_size); if (status != 0) err_abort (status, "Get stack size"); printf ("Default stack size is %u; minimum is %u\n", stack_size, PTHREAD_STACK_MIN); status = pthread_attr_setstacksize ( &thread_attr, PTHREAD_STACK_MIN*2); if (status != 0) err_abort (status, "Set stack size");#endif status = pthread_create ( &thread_id, &thread_attr, thread_routine, NULL); if (status != 0) err_abort (status, "Create thread"); printf ("Main exiting\n"); pthread_exit (NULL); return 0;}

 

 

 

转载于:https://www.cnblogs.com/wangfengju/archive/2013/05/08/6173125.html

你可能感兴趣的文章
apache自带压力测试工具ab的使用及解析
查看>>
C#使用Xamarin开发可移植移动应用(2.Xamarin.Forms布局,本篇很长,注意)附源码
查看>>
jenkins搭建
查看>>
C#中使用Split分隔字符串的技巧
查看>>
加固linux
查看>>
IPSP问题
查看>>
10.17动手动脑
查看>>
WPF中Image显示本地图片
查看>>
php仿阿里巴巴,php实现的仿阿里巴巴实现同类产品翻页
查看>>
面对问题,如何去分析?(日报问题)
查看>>
nodejs vs python
查看>>
poj-1410 Intersection
查看>>
Java多线程基础(一)
查看>>
SQL Server中利用正则表达式替换字符串
查看>>
POJ 1015 Jury Compromise(双塔dp)
查看>>
Python3 高阶函数
查看>>
初始面向对象
查看>>
leetcode Letter Combinations of a Phone Number
查看>>
Unity 5.4 测试版本新特性---因吹丝停
查看>>
7.5 文件操作
查看>>