免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2647 | 回复: 13
打印 上一主题 下一主题

[新手入门] 找aix下线程编程的高手 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-10-16 14:05 |只看该作者 |倒序浏览
在程序执行的时候按Ctrl+C,产生了core。
请教是怎么会事?应该怎么处理
#include <stdio.h>;
#include <errno.h>;
#include <sys/types.h>;
#include <sys/socket.h>;
#include <sys/signal.h>;
#include <sys/select.h>;
#include <sys/sem.h>;
#include <netinet/in.h>;
#include <pthread.h>;

pthread_mutex_t mutex;
pthread_cond_t  cond;
pthread_t       tid, tid2, tid3;

void *thread_start(void *arg)
{

  while(1)
  {
   pthread_mutex_lock(&mutex);

    if( pthread_cond_wait(&cond,&mutex) == EINTR )
    {
      printf("eintr...............\n";
    }
    pthread_mutex_unlock(&mutex);
  }
  pthread_exit(0);
}

void killHandle(int signo)
{
  printf("get here.\n";
  pthread_mutex_destroy(&mutex);
  pthread_cond_destroy(&cond);
  exit(-2);
}
int createthread(void)
{

  pthread_mutex_init(&mutex,NULL);
  pthread_cond_init(&cond, NULL);
  
  pthread_create(&tid, NULL, thread_start, NULL);

  pthread_create(&tid2, NULL, thread_start, NULL);
  pthread_create(&tid3, NULL, thread_start, NULL);
  
}
int main(void)
{
  int sockfd   = -1;
  int ret      = 0;
  int listenfd = 0;
  struct sockaddr_in server_addr;
  

  signal(SIGTERM, killHandle);
  signal(SIGINT,  killHandle);
  signal(SIGPIPE, killHandle);
  
  createthread();
  
  sockfd = socket(AF_INET, SOCK_STREAM, 0 );
  if( sockfd == -1 )
  {
    printf("getSocket:socket create error.\n";
    return -1;
  }
  
  server_addr.sin_family      = AF_INET;
  server_addr.sin_port        = htons(50001);
  server_addr.sin_addr.s_addr = INADDR_ANY;
  bzero(&(server_addr.sin_zero), ;

  ret = bind(sockfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
  if( ret == -1 )
  {
    printf("getSocket:socket bind error.\n";
    return -1;
  }
  listenfd = listen(sockfd, 120);
   

  for( ;; )
  {
    printf("main:get here 1\n";   
    ret = select(sockfd+1, NULL, NULL, NULL, NULL);
    if( ret == EINTR )
    {
      printf("main: eintr\n";
      return 0;
    }
    printf("main:get here 2\n";   
  }   
  return 0;
}

论坛徽章:
0
2 [报告]
发表于 2004-10-16 23:03 |只看该作者

找aix下线程编程的高手

what's the debug msg of the core ?

论坛徽章:
0
3 [报告]
发表于 2004-10-18 12:40 |只看该作者

找aix下线程编程的高手

Segmentation fault in spin_lock_global_ppc_up at 0xd0019828
0xd0019828 (spin_lock_global_ppc_up+0x 90c40154        stw   r6,0x154(r4)

等待楼上仁兄的答案,谢谢

论坛徽章:
0
4 [报告]
发表于 2004-10-18 14:36 |只看该作者

找aix下线程编程的高手

我现在把子线程的中断信号屏蔽了,这样只让父线程获得中断信号,就没有问题了。前几天可能是我在屏蔽信号的时候写错了代码,所以没有看到效果。
谢谢大家!

论坛徽章:
0
5 [报告]
发表于 2004-10-18 14:37 |只看该作者

找aix下线程编程的高手

oh, seems your killHandle( ) destroy the mutex before all threads can be exited.

After KillHandle( ), mutex is a invalid address, then further address invoke Segmentation fault.

In KillHandle( ), first killall all threads, then destroy the mutex.

I'm not sure about it, but I feel it is worthy a try



And what's the output of "where" in debuger ?

论坛徽章:
0
6 [报告]
发表于 2004-10-18 14:40 |只看该作者

找aix下线程编程的高手

Also do you have AIX's native c compiler ?

Currently I'm developing  an AIX PCI device driver. Always encounter error on BUS attached I/O, and I doubt if it is the problem of Gcc I used. If you have it, pls help me

论坛徽章:
0
7 [报告]
发表于 2004-10-23 10:20 |只看该作者

找aix下线程编程的高手

(dbx) where
_vp_sleep(??, ??) at 0xd0012908
_usched_dispatch(??, ??, ??) at 0xd0010fe8

你说的很有道理,我也知道这个原因,问题在kill all thread的时候没有找到很好的方法。

论坛徽章:
0
8 [报告]
发表于 2004-10-23 10:31 |只看该作者

找aix下线程编程的高手

另:不好意思,我在主机上没有找到Gcc
只有C for AIX Compiler, Version 6和C for AIX Compiler, Version 5
我没有编译器的安装软件,sorry!
如果你是想让我做个测试,乐意帮忙!

论坛徽章:
0
9 [报告]
发表于 2004-10-23 10:36 |只看该作者

找aix下线程编程的高手

where are you then, bj ?

论坛徽章:
0
10 [报告]
发表于 2004-10-25 09:31 |只看该作者

找aix下线程编程的高手

现在在上海!
一个到处飘的人,就差北京没去了,说不出来是遗憾还是其他什么了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP