posix多线程有感--线程高级编程(线程属性函数总结)(代码)
来源:互联网 发布:淘宝买东西返利软件 编辑:程序博客网 时间:2024/06/07 05:11
/* * 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 <limits.h>#include <pthread.h>#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;}
- posix多线程有感--线程高级编程(线程属性函数总结)
- posix多线程有感--线程高级编程(线程属性函数总结)(代码)
- posix多线程有感--线程高级编程(线程属性pthread_attr_t)
- posix多线程有感--线程高级编程(线程属性pthread_attr_t)---实时调度(代码)
- posix多线程有感--线程高级编程(互斥量属性)
- posix多线程有感--线程高级编程(条件变量属性)
- posix多线程有感--线程高级编程(互斥量属性)(代码)
- posix多线程有感--线程高级编程(线程属性pthread_attr_t)---实时调度
- posix多线程有感--线程高级编程(线程内存模式)
- posix多线程有感--线程高级编程(线程堆栈)
- posix多线程有感--线程高级编程(条件变量)
- posix多线程有感--线程高级编程(pthread_once)
- posix多线程有感--线程高级编程(pthread_key_t)
- posix多线程有感--线程高级编程(进程的优先级)
- posix多线程有感--线程高级编程(优先级有关)
- posix多线程有感--线程高级编程(条件变量)
- posix 多线程有感--线程
- posix多线程有感--线程高级编程(线程和fork,exec)
- 如何学习c语言
- 程序员不错的网站
- Android自制发送短信程序
- 缓存图片并显示的ImageView
- 详解iOS开发之将XML转换成树
- posix多线程有感--线程高级编程(线程属性函数总结)(代码)
- 推荐系统思考小结(基于Mahout)
- MTK
- 目标检测的图像特征提取之(二)LBP特征
- 程序员技术练级攻略
- SQL函数大全
- C#解析xml(获取指定节点值)
- 笔记:Linux Shell (五):标准输入输出重定向
- mysql+hibernate数据库查询问题