#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. odoo XMLRPC 新库 OdooRPC 尝鲜

    无意中发现了python居然有了OdoRPC的库,惊喜之下赶紧尝试一番,比XMLRPC简洁了不少,机制看样子是利用的JsonRPC. #原文出自KevinKong的博客http://www.cnblo ...

  2. 获取行间样式与在js中设置样式

    !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/x ...

  3. 一款名為com.apple.pcapd的服務

    一款名為com.apple.pcapd的服務,通過libpcap網路數據包捕獲函數包捕獲流入和流出iOS設備的HTTP數據.據紮德爾斯基稱,這一服務在所有iOS設備上都是默認啟動的,能被用來在用戶不知 ...

  4. BizTalk开发系列(十二) Schema设计之Group与Order

    开发BizTalk项目的时候会先约定各系统之间往来的消息格式. 由于BizTalk内部唯一使用XML文档.因此消息的格式为XML Schema(XML Schema 用于描述 XML 文档的结构).虽 ...

  5. Android课程---布局管理器

  6. IOS第九天(1:QQ聊天界面frame模型)

    ///  控制层 #import "HMViewController.h" #import "HMMessageModel.h" #import "H ...

  7. 实现memcpy

    memcpy的原型: SYNOPSIS #include <string.h> void *memcpy(void *dest, const void *src, size_t n); D ...

  8. Java Collection框架详解

    引用自:http://blog.sina.com.cn/s/blog_6d6f5d7d0100s9nu.html 经常会看到程序中使用了记录集,常用的有Collection.HashMap.HashS ...

  9. 【7集iCore3基础视频】7-2 iCore3原理图介绍

    iCore3原理图介绍: 高清源视频:http://pan.baidu.com/s/1hsPkifM 密码:ei8ciCore3 购买链接:https://item.taobao.com/item.h ...

  10. Json的语法及使用方法

    Json的语法及使用方法 Json(JavaScript Object Notation)对象表示标识,是一种轻量级的数据交换语言,比XML更容易解析,独立于语言和平台. 语法规则: 对象用{}保存 ...