#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. Java.lang.NoSuchFieldError: INSTANCE异常

    解决方案: java.lang.NoSuchFieldError: INSTANCE异常. 1.jar包重复了. 2.版本还不相同,如果包的版本不同也会报相应的错,不过一般情况自己导入的jar包主要看 ...

  2. Logistic Regression Vs Decision Trees Vs SVM: Part I

    Classification is one of the major problems that we solve while working on standard business problem ...

  3. html使用心得

    (1)<textarea style= "word-break:break-all" rows="5" cols="20"> 在 ...

  4. [NoSQL]验证redis的主从复制

    安装配置redis  http://www.cnblogs.com/myrunning/p/4222385.html 1.1查看当前redis文件 1.2修改配置文件 拷贝配置文件分别为redis_m ...

  5. 解决谷歌浏览器和360浏览器 input 自动填充淡黄色背景色的问题

     input:-webkit-autofill {-webkit-box-shadow: 0 0 0px 1000px white inset;}

  6. find a multiple

    Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of ...

  7. 词频junit测试

    package search; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; impor ...

  8. php使用p3p实现cookies跨域设置 实现单点登录,全站登录

    P3P Header is present: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC ...

  9. mongo vue的常用操作

    查找在某个范围内的记录: {"_id":{$in: [a,b,c]}}     如果images是个数组,则查询方式与普通数据一样:{"images":&quo ...

  10. Intelligencia.UrlRewriter在IIS 7.0下的完全配置攻略

    在项目中,之前公司是使用IIS 7.0官方的URL重写模块,官方的使用说明请参见官方URLRewrite  ,添加伪静态支持,后来经理问我有没有涉及伪静态,我说之前项目中我一直是用Intelligen ...