当前位置: 技术问答>linux和unix
请教一下各位高手,为什么fifo管道在线程内总是write失败?
来源: 互联网 发布时间:2016-11-17
本文导语: void *thread_read( void *arg ){ int len,sock_fd,pipe_fd; char signal_bit = 1; char buffererq[1024]; bool Readenable = false; while( true ){ printf( "enter the thread!n" ); pthread_mutex_lock( &mutex ); if(0...
void *thread_read( void *arg ){
int len,sock_fd,pipe_fd;
char signal_bit = 1;
char buffererq[1024];
bool Readenable = false;
while( true ){
printf( "enter the thread!n" );
pthread_mutex_lock( &mutex );
if(0 != msg[msg_location_read%( 1024*1024 )] ){
sock_fd = msg[msg_location_read%( 1024*1024 )];
msg[msg_location_read%( 1024*1024 )] = 0;
msg_location_read++;
Readenable = true;
}
pthread_mutex_unlock( &mutex );
if( Readenable ){
read( sock_fd, buffererq, 1024 );
printf( "thread %d have rev the msg:%sn", getpid( ), buffererq);
Readenable = false;
pthread_mutex_lock( &mutex_on_fifo );
pipe_fd = open( "fifo_read", O_WRONLY|O_NONBLOCK );
write( "fifo_read", signal_bit, sizeof( signal_bit ) );
close( pipe_fd );
pthread_mutex_lock( &mutex_on_fifo );
}
sleep( 10 );
}
}
|
而且第二个参数也不对啊,应该是一个指针
write( pipe_fd, &signal_bit, sizeof( signal_bit ) );
write( pipe_fd, &signal_bit, sizeof( signal_bit ) );
|
pipe_fd = open( "fifo_read", O_WRONLY|O_NONBLOCK );
if(pipe_fd
if(pipe_fd