delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/05/09/14:52:05

X-Spam-Check-By: sourceware.org
Date: Tue, 9 May 2006 20:51:45 +0200 (MEST)
From: "Ivan Mari" <ivanmari AT gmx DOT net>
To: cygwin AT cygwin DOT com
MIME-Version: 1.0
Subject: pthread_cond_timedwait not reporting error on bad arg.
X-Authenticated: #7976413
Message-ID: <9419.1147200705@www106.gmx.net>
X-Mailer: WWW-Mail 1.6 (Global Message Exchange)
X-Flags: 0001
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

In the code below, the timespec argument to pthread_cond_timedwait() is set
to an invalid value: t_nsec > 999,999,999 so, EINVAL error code should be
returned.

Regards,

Ivan Mari

#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <errno.h>


void* start_routine( void* arg );

pthread_cond_t m_cond = PTHREAD_COND_INITIALIZER;

pthread_mutex_t m_lock  = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

int main()
{
  
  struct timespec t;
  
  t.tv_nsec = 1000000000; /* This value should be in the range 0 < tv_nsec <
999999999 */
  t.tv_sec = 1145259964;

  pthread_mutex_lock( &m_lock );
  
  printf("Entering cond wait \n");
  
  int rv = pthread_cond_timedwait( &m_cond, &m_lock, &t );

  if( rv )
  {
	switch( rv )
	{
		case ETIMEDOUT:
		  printf("Error timeout before receiving signal\n");
		  break;
		
		case EINVAL:
		  printf("Error invalid abstime or mutex or cond\n");
		  break;
				
		case EPERM:
		  printf("Error thread doesn't own mutex\n");
		  break;
	}

  }

  printf("pthread_cond_wait returned %d\n",rv);
  pthread_mutex_unlock( &m_lock );
  return 0;

  
}

-- 
Echte DSL-Flatrate dauerhaft für 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019