23,217
社区成员




void main(int argc, char **argv)
{
initMutex();
initial_udp();
// thread A 代码,放在一个函数里了
udp_process();
// 这个函数里,开启了 一个线程,方法和下面的一样。 单独一下线程运行,一切正常。
// thread B 开始
/*
初始化属性值,均设为默认值
*/
pthread_attr_init(&attr2);
pthread_attr_setscope(&attr2, PTHREAD_SCOPE_SYSTEM);
pthread_attr_setdetachstate(&attr2, PTHREAD_CREATE_DETACHED);
if(pthread_create(&thread_loop_print,&attr2,(void*)pthread_handle_message2,NULL))
{
perror("pthread_creat error!");
exit(-1);
}
// thread B 结束
// udp_process();
while(1)
{}
//return 0;
}
setting rlimit success!
Starting listening
IP and port bind ��
IP : 192.168.34.52
port: 1234
socket adding in epoll success!
kdpfd values: 8
nfds values: 1
[New Thread 0xb7e06b40 (LWP 23579)]
kdpfd values: 8
socket 7 recv from : 192.168.34.33 : 8089 message: @� 4 bytes
Hex bytes:
400202BC
Data length:8
F0 06 02 00 11 22 33 44
nfds values: -1
epoll_wait error!
: Interrupted system call
[Thread 0xb7e06b40 (LWP 23579) exited]
[New Thread 0xb7605b40 (LWP 23580)]
this is thread 2!
[New Thread 0xb7e06b40 (LWP 23581)]
this is thread 3!
this is thread 2!
this is thread 2!
this is thread 3!
this is thread 2!
this is thread 2!
this is thread 2!
this is thread 3!
this is thread 2!
this is thread 2!
this is thread 2!
this is thread 3!
this is thread 2!
this is thread 2!
this is thread 2!
this is thread 3!
this is thread 2!
用GDB 调试时, udp_process(); 开启最先,,有数据来时,里面线程能正常运行一次,后面就报错了
但是, thread A 和 thread B 能正常循环打印 字符串
不在调试模式时,,全速跑
只有, udp_process(); 能正常运行,, thread A 和 thread B 不能打印...
udp_process();
/*
初始化属性值,均设为默认值
*/
pthread_attr_init(&attr2);
pthread_attr_setscope(&attr2, PTHREAD_SCOPE_SYSTEM);
pthread_attr_setdetachstate(&attr2, PTHREAD_CREATE_DETACHED);
if(pthread_create(&thread_loop_print,&attr2,(void*)pthread_handle_message2,NULL))
{
perror("pthread_creat error!");
exit(-1);
}
if(pthread_create(&thread_loop_print2,&attr2,(void*)pthread_handle_message3,NULL))
{
perror("pthread_creat error!");
exit(-1);
}
又加了个打印线程函数
如果, udp_process(); (这个函数里封装的线程),参与执行,则后面两个线程都不能执行,
如果 udp_process(); 这个先屏蔽掉,,后面两个线程都能各自打印 字符串信息出来,也就是后面两个线程OK
基本可以肯定 udp_process(); 这个函数里封装的线程的问题,,估计是哪里出了问题?