To set a pthread_cond_timedwait() ?

Joel Sherrill joel.sherrill at oarcorp.com
Fri Feb 17 21:35:48 UTC 2006


Matteo wrote:

>Scrive Joel Sherrill <joel.sherrill at oarcorp.com>:
>
>  
>
>>Matteo wrote:
>>
>>    
>>
>>>Hi 
>>>following the psx example I try to use the  pthread_cond_timedwait() but it
>>>      
>>>
>>>returns me an error, but I think to have set all I have to set, may be I 
>>>forget to define some condition ?
>>>Here there is my little example, it compiles but when it works I have an
>>>      
>>>
>>error 
>>    
>>
>>>on the condition timed. 
>>>
>>> 
>>>
>>>      
>>>
>>You do not have a call to pthread_cond_init or pthread_mutex_init
>>    
>>
>
>Sorry you get reason, I just forget to copy the initialization in the text file 
>below :),
>In the original is there the initilization but the problem is the same
>Have you an idea about my error ?
>
>  
>
Not really.  Have you checked out the class examples from CVS and looked 
at them?
You probably have a very simple mistake that you are just missing. 

Can you debug and step into the failing calls?  That's what I did with 
your code. :)

--joel

>>See class-examples/pthread_cond_server.
>>
>>--joel
>>
>>    
>>
>#include <bsp.h>
>#include <pthread.h>
>#include <stdlib.h>
>#include <stdio.h>
>#include <sched.h>
> pthread_mutex_t mutex;
> pthread_cond_t cond;
> void * print_hello(void * arg)
>  {
>  struct timeval time;
>  struct timespec timeout;
>  gettimeofday(&time, NULL);
>  timeout.tv_sec = time.tv_sec + 2;
>  timeout.tv_nsec = time.tv_usec * 1000;
>  printf("<child>: Hello World coming to wait!\n");
>
>  if (pthread_cond_timedwait(&cond, &mutex, &timeout)) perror ("Error on 
>TIMEDWAIT");
>
>  printf("<child>: Hello World exit to wait!\n");
>  return NULL;
>  }
>int *POSIX_Init()
> {
> pthread_t child;
>
> pthread_mutex_init(mutex, NULL);  
> pthread_cond_init(cond, NULL);
>
> if ( pthread_create( &child, NULL, print_hello, NULL )) perror("Error on 
>create");
>  printf("<main>: Wait for child thread...\n");
>  if ( pthread_join( child, NULL )) perror ("Errore sulla join");
>  return 0;
>  }
>#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
>#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
>#define CONFIGURE_MAXIMUM_POSIX_THREADS              10
>#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES  10
>#define CONFIGURE_MAXIMUM_POSIX_MUTEXES              10
>#define CONFIGURE_POSIX_INIT_THREAD_TABLE
>#define CONFIGURE_INIT
>#include <rtems/confdefs.h>
>
>
>
>  
>




More information about the users mailing list