strange behaviour with pthread_cond_wait()

Daniel Valencia fetrovsky at yahoo.com
Wed Aug 31 00:35:40 GMT 2005


Hello, everybody...

I have this multithreaded program, and there are these
two threads that work together with a queue.  The
backend receive thread reads packets and pushes them
into the queue, while the frontend thread pops them
off the queue to hand them to the caller.  This is an
implementation of a software switch.

The issue is, i have this little piece of code in the
thread which actually performs the popping:

  if( !_recvq.size() )
  {
    int e = pthread_cond_wait( &_thread_cond_recv,
                   &_thread_mutex_recv );

    if( e )
    {
      std::perror( "pthread_cond_wait" );
      std::exit( e );
    }
  }

  pthread_mutex_lock( &_recvq_mutex );
  p = _recvq.front();
  _recvq.pop();
  pthread_mutex_unlock( &_recvq_mutex );

And when I runn my program, it will immediately exit. 
The message is:

pthread_cond_wait: Unknown error: 0

Not only that: the returned value (e) is 1, while
EINVAL is 22.  According to the man pages, if
successful, pthread_cond_wait() will return 0; else,
it will return a value indicating the error (the only
possible value being EINVAL).

My mutex address is not NULL, for I am taking the
address of an automatic object (I checked anyways).

Any hints will be greatly appreciated.



Thank you,


Daniel


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the freebsd-hackers mailing list