#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#define THREAD_COUNT 12 void show_thread_policy(int threadno){
int policy;
struct sched_param param;
pthread_getschedparam(pthread_self(), &policy, &param);
switch(policy){
case SCHED_OTHER:
printf("SCHED_OTHER %d\n", threadno);
break;
case SCHED_RR:
printf("SCHED_RR %d\n", threadno);
break;
case SCHED_FIFO:
printf("SCHED_FIFO %d\n", threadno);
break;
default:
printf("UNKNOWN\n");
}
} void *thread(void *arg){
int i,j;
long threadno = (long)arg;
printf("thread %d start \n", threadno);
printf("thread ------------------------------0\n");
sleep();
printf("---------1---------------\n");
show_thread_policy(threadno);
printf("---------2---------------\n");
for(int i=;i<;i++){
printf("---------3---------------\n");
for(j=;j<;j++){ } printf("thread %d\n", threadno);
} printf("thread %d exit\n", threadno);
return NULL;
} int main(int argc, char *argv[]){
long i;
pthread_attr_t attr[THREAD_COUNT];
pthread_t pth[THREAD_COUNT];
struct sched_param param;
for(i=;i<THREAD_COUNT;++i){
pthread_attr_init(&attr[i]);
for(i=;i<THREAD_COUNT/;++i){
param.sched_priority = ;
pthread_attr_setschedpolicy(&attr[i], SCHED_FIFO);
pthread_attr_setschedparam(&attr[i], &param);
pthread_attr_setinheritsched(&attr[i], PTHREAD_EXPLICIT_SCHED);
} for(i=THREAD_COUNT/;i<THREAD_COUNT;++i){
param.sched_priority = ;
pthread_attr_setschedpolicy(&attr[i], SCHED_FIFO);
pthread_attr_setschedparam(&attr[i], &param);
pthread_attr_setinheritsched(&attr[i], PTHREAD_EXPLICIT_SCHED);
} for(i=;i<THREAD_COUNT;++i){
pthread_create(&pth[i], &attr[i], thread, (void *)i);
printf("--------------------create thread %d------------\n", i);
} for(i=;i<THREAD_COUNT;++i){
pthread_join(pth[i], NULL);
} for(i=;i<THREAD_COUNT;++i){
pthread_attr_destroy(&attr[i]);
} return ;
}
}

编译之后执行的结果如下:

[root@Alston C++]# ./thread_2.exe
thread 0 start
thread ------------------------------0
--------------------create thread 0------------
--------------------create thread 1------------
--------------------create thread 2------------
--------------------create thread 3------------
Segmentation fault (core dumped)

目前还没调查出来原因。

create thread的时候发生core dump的更多相关文章

  1. linux core dump 文件 gdb分析

    core dump又叫核心转储, 当程序运行过程中发生异常, 程序异常退出时, 由操作系统把程序当前的内存状况存储在一个core文件中, 叫core dump. (linux中如果内存越界会收到SIG ...

  2. core dump gdb调试

    core dump又叫核心转储, 当程序运行过程中发生异常, 程序异常退出时, 由操作系统把程序当前的内存状况存储在一个core文件中, 叫core dump. (linux中如果内存越界会收到SIG ...

  3. Linux Core Dump

    当程序运行的过程中异常终止或崩溃,操作系统会将程序当时的内存状态记录下来,保存在一个文件中,这种行为就叫做Core Dump(中文有的翻译成“核心转储”).我们可以认为 core dump 是“内存快 ...

  4. 【转】段错误调试神器 - Core Dump详解

    from:http://www.embeddedlinux.org.cn/html/jishuzixun/201307/08-2594.html 段错误调试神器 - Core Dump详解 来源:互联 ...

  5. Segment fault及LINUX core dump详解 (zz)

    C 程序在进行中发生segment fault(core dump)错误,通常与内存操作不当有关,主要有以下几种情况: (1)数组越界. (2)修改了只读内存. (3)scanf("%d&q ...

  6. 【转】 Linux Core Dump 介绍

    ===============================================================  Linux core dump的祥细介绍和使用 =========== ...

  7. 段错误调试神器 - Core Dump详解

    一.前言: 有的程序可以通过编译, 但在运行时会出现Segment fault(段错误). 这通常都是指针错误引起的. 但这不像编译错误一样会提示到文件某一行, 而是没有任何信息, 使得我们的调试变得 ...

  8. Linux Core Dump【转】

    转自:http://www.cnblogs.com/hazir/p/linxu_core_dump.html 当程序运行的过程中异常终止或崩溃,操作系统会将程序当时的内存状态记录下来,保存在一个文件中 ...

  9. linux下core dump

    1.前言 一直在从事linux下后台开发,经常与core文件打交道.还记得刚开始从事linux下开发时,程序突然崩溃了,也没有任何日志.我不知所措,同事叫我看看core,我却问什么是core,怎么看. ...

随机推荐

  1. 集合 ArrayList 类

    集合的基本信息: System.Collections   系统类中的收藏类,定义各种对象(如列表,队列,位数组,哈希表和字典)的集合 常用的集合为ArrayList类:特殊集合一般会用到Queue队 ...

  2. IO字 节流/字符流 读取/写入文件

    流是指一连串流动的数据信号,以先进,先出的方式发送和接收的通道 流的分类根据方向分为输入流所有接收,获得,读取的操作都是属于输入流所有的输入流名字都带有input或Reader 输出流所有发送,写的操 ...

  3. c++用双向链表实现模板栈

      可直接编译运行,其中方法status为形象的显示出栈的结构: // visual stack , need define "cout<<" #include < ...

  4. H5学习小结——div+css创建电子商务静态网页

    使用Sublime Text软件编写电子商务类网站静态形式首页 经过差不多一星期的学习,基本掌握了div+css的用法之后,开始了实战练习.首先要做的就是要练习一下一般电子商务网页的编写,我做的是下图 ...

  5. C# MD5加密的方法+一般处理程序使用Session+后台Json序列化

    1.MD5加密 string md5Str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s ...

  6. ubuntu安装配置jdk tomcat mysql ...

    安装之前大家一定要检查好各个版本问题 以免造成不兼容. (一)下载所需安装包: jdk-7u76-linux-x64.tar.gz apache-tomcat-7.0.63.tar.gz MySQL- ...

  7. BizTalk开发系列(二十九) 宏的使用

    在BizTalk中可以使用宏集合动态的让BizTalk发送处理程序使用单独的值来替换宏.常用的使用宏的发送程序有:文件发送适配器和SMTP发送适 配器.在表达式中可以使用同时使用多个宏.例如:在文件发 ...

  8. 故障处理-ORA-00376/ORA-01110

    数据库实例启动之后发现,9号数据文件发生故障,file 9 cannot be read at this time, ORACLE Instance ilndb2 (pid = 16) - Error ...

  9. ios-WKWebView 拨打电话

    -(void)webView:(WKWebView* )webView didStartProvisionalNavigation:(WKNavigation* )navigation { NSStr ...

  10. vsftpd增加ssl安全验证

    查看vsftpd是否支持ssl ldd `which vsftpd`|grep ssl 输出 libssl.so.6 => /lib64/libssl.so.6 (0x00002ba684304 ...