当前位置: 技术问答>linux和unix
初学,大家帮忙看下,我在make时总是出现创建线程失败的错误报告,为什么呢?
来源: 互联网 发布时间:2015-12-04
本文导语: 一,文件serial.h: #ifndef _serial_h_ #define _serial_h_ #include /*termios是tty一种*/ #include #include #include #include #include ...
一,文件serial.h:
#ifndef _serial_h_
#define _serial_h_
#include /*termios是tty一种*/
#include
#include
#include
#include
#include
#include /*struct time*/
#include
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyS1" /*!第二个串口*/
#define _POSIX_SOURCE 1 /*! POSIX compliant source */
#define FALSE 0
#define TRUE 1
struct timeval timeout; /*用于select中设定超时*/
extern void signal_handler_IO (int status); /* definition of signal handler */
int fd, c, res, i, ii, num;
extern void process();
extern void process2();
extern void signal_handler_IO (int status);
#endif
二,文件serial3.c
#include /*termios是tty一种*/
#include
#include
#include
#include
#include
#include /*struct time*/
#include "serial.h"
#include
void main()
{
int error,ffd;
int error2,ffd2;
pthread_t tid;
pthread_attr_t tattr;
pthread_t tid2;
pthread_attr_t tattr2;
void process();
void process2();
if((error=pthread_attr_init(&tattr))==0)
fprintf(stderr,"Failed to creat attribute object:%sn",
strerror(error));
else if((error=pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED))==0)
fprintf(stderr,"Failed to set attribute state to detached:%sn",
strerror(error));
else if((error=pthread_create(&tid,&tattr,(void *)&process,&ffd))==0)
{fprintf(stderr,"Failed to creat the pthread:%sn",
strerror(error));
}
if((error=pthread_attr_init(&tattr2))==0)
fprintf(stderr,"Failed to creat attribute object:%sn",
strerror(error2));
else if((error=pthread_attr_setdetachstate(&tattr2,PTHREAD_CREATE_DETACHED))==0)
fprintf(stderr,"Failed to set attribute state to detached:%sn",
strerror(error2));
else if((error=pthread_create(&tid2,&tattr2,(void *)&process2,&ffd2))==0)
{fprintf(stderr,"Failed to creat the pthread:%sn",
strerror(error2));
}
}
三,文件hehe.c:
#include /*termios是tty一种*/
#include
#include
#include
#include
#include
#include /*struct time*/
#include "serial.h"
#include
char buf[255];
char rec[255];
fd_set readset; /*用select调用时必须用的结构*/
volatile int STOP=FALSE; /*volatile 指出stop是随时可能发生变化的,每次使用它的时候必须从它的地址中读取
void signal_handler_IO (int status); /* definition of signal handler */
int wait_flag=TRUE; /* TRUE while no signal received */
int flag=0;
int recv_times=0;
int fd, c, res, i, ii, num;
void process()
{
struct termios oldtio,newtio;
struct sigaction saio; /*信号操作码有3个参数 */
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd
#ifndef _serial_h_
#define _serial_h_
#include /*termios是tty一种*/
#include
#include
#include
#include
#include
#include /*struct time*/
#include
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyS1" /*!第二个串口*/
#define _POSIX_SOURCE 1 /*! POSIX compliant source */
#define FALSE 0
#define TRUE 1
struct timeval timeout; /*用于select中设定超时*/
extern void signal_handler_IO (int status); /* definition of signal handler */
int fd, c, res, i, ii, num;
extern void process();
extern void process2();
extern void signal_handler_IO (int status);
#endif
二,文件serial3.c
#include /*termios是tty一种*/
#include
#include
#include
#include
#include
#include /*struct time*/
#include "serial.h"
#include
void main()
{
int error,ffd;
int error2,ffd2;
pthread_t tid;
pthread_attr_t tattr;
pthread_t tid2;
pthread_attr_t tattr2;
void process();
void process2();
if((error=pthread_attr_init(&tattr))==0)
fprintf(stderr,"Failed to creat attribute object:%sn",
strerror(error));
else if((error=pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED))==0)
fprintf(stderr,"Failed to set attribute state to detached:%sn",
strerror(error));
else if((error=pthread_create(&tid,&tattr,(void *)&process,&ffd))==0)
{fprintf(stderr,"Failed to creat the pthread:%sn",
strerror(error));
}
if((error=pthread_attr_init(&tattr2))==0)
fprintf(stderr,"Failed to creat attribute object:%sn",
strerror(error2));
else if((error=pthread_attr_setdetachstate(&tattr2,PTHREAD_CREATE_DETACHED))==0)
fprintf(stderr,"Failed to set attribute state to detached:%sn",
strerror(error2));
else if((error=pthread_create(&tid2,&tattr2,(void *)&process2,&ffd2))==0)
{fprintf(stderr,"Failed to creat the pthread:%sn",
strerror(error2));
}
}
三,文件hehe.c:
#include /*termios是tty一种*/
#include
#include
#include
#include
#include
#include /*struct time*/
#include "serial.h"
#include
char buf[255];
char rec[255];
fd_set readset; /*用select调用时必须用的结构*/
volatile int STOP=FALSE; /*volatile 指出stop是随时可能发生变化的,每次使用它的时候必须从它的地址中读取
void signal_handler_IO (int status); /* definition of signal handler */
int wait_flag=TRUE; /* TRUE while no signal received */
int flag=0;
int recv_times=0;
int fd, c, res, i, ii, num;
void process()
{
struct termios oldtio,newtio;
struct sigaction saio; /*信号操作码有3个参数 */
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd