To set a pthread_cond_timedwait() ?
Joel Sherrill
joel.sherrill at oarcorp.com
Fri Feb 17 20:25:48 UTC 2006
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.
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;
> if ( pthread_create( &child, NULL, print_hello, NULL )) perror("Errore sulla
>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>
>
>Thanks
>
>Matteo
>
>
>
>
More information about the users
mailing list