What's wrong in this simple posix example ?

Matteo matteo.posterli at studenti.unipr.it
Thu Mar 2 09:17:17 UTC 2006


Thanks for the suggestion but the system still crash, the problem is the the
task with lowest priority is never launched, but I don't know why!
Someone have some idea ?

Thanks in advance

Matteo


Scrive Sergei Ablalimov <sa at design.morion.ru>:

> Hello Matteo,
> I run your sample and see:
> 
> <main> Enter in the main
> Creating first task                                                          
>   
> <child>: Hello World! task with max priority                                 
>   
> First Task created                                                           
>   
> The task is coming to enter in a timed wait                                  
>   
> Creating second task                                                         
>   
> Second task created                                                          
>   
> <main> Out of the main                                                       
>   
> The task is coming out from the timed wait   
> 
> After that - crash.
> using rtems_task_delete(RTEMS_SELF) instead of exit resolve problem.
> 
> Thursday, March 2, 2006, 4:53:11 AM, you wrote:
> 
> 
> > Hi
> > I'm working with posix thread and I'm trying to launch 2 thread with
> different
> > priority but I have a lot of error of memory but I'm using a really simple
> > example of one threads that uses a timed wait and onother one that is
> simple
> > launched. 
> > The code is just below ;
> 
> > #include <sched.h>
> > #include <bsp.h>
> > #include <stdlib.h>
> > #include <stdio.h>
> > #include <pthread.h>
> 
> >   pthread_mutex_t mutex;
> >   pthread_cond_t cond;
> >   struct timespec timeout;
> >   struct sched_param param;
> >   pthread_attr_t attr;
>   
> > void * print_hello(void * arg){
> >   printf("<child>: Hello World! task with max priority \n");
> >   clock_gettime( CLOCK_REALTIME, &timeout );
> >   timeout.tv_sec += 3;
> >   timeout.tv_nsec = 0;
> >   printf("The task is coming to enter in a timed wait\n");
> >   pthread_cond_timedwait(&cond, &mutex, &timeout);
> >   printf("The task is coming out from the timed wait \n");
> >   return NULL;
> > }
> 
> > void * print_hello_a(void * arg){
> >   printf(" <child>: Hello World! Task with lowest priority ");
> >   return NULL;
> > }
> 
> 
> > void *POSIX_Init()
> > {
> >   pthread_t child1;
> >   pthread_t child2;
> >   pthread_attr_init(&attr);
> >   pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
> >   pthread_mutex_init( &mutex, NULL );
> >   pthread_cond_init( &cond, NULL );
> 
> >   printf("<main> Enter in the main \n");
> 
> >   printf("Creating first task \n");
> >   param.sched_priority = sched_get_priority_max(SCHED_FIFO);
> >   pthread_attr_setschedparam(&attr, &param);
> >   if ( pthread_create( &child1, &attr, print_hello, NULL) || 
> > pthread_setschedparam(child1, SCHED_FIFO, &param) ) {
> >   printf("Thread cannot be created or you have not enough privileges to
> set
> > priority!!!!\n");
> >   exit(1);
> >   }
> >   printf("First Task created \n");
> >   printf("Creating second task \n");
> >   param.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
> >   pthread_attr_setschedparam(&attr, &param);
> >   if ( pthread_create( &child2, &attr, print_hello_a, NULL) || 
> > pthread_setschedparam(child2, SCHED_FIFO, &param) ) {
> >         printf("Thread cannot be created or you have not enough privileges
> to
> > set priority!!!!\n");
> >         exit(1);
> >   }
> >   printf("Second task created \n");
> 
> > printf("<main> Out of the main\n");
> >   pthread_join( child1, NULL );
> >   pthread_join( child2, NULL );
> 
> >   exit(0);
> > }
> > #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> > #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
> > #define CONFIGURE_TEST_NEEDS_TIMER_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>
> 
> 
> > What's wrong?
> > I don't understand what could be the problem!
> > Someone can help me ?
> 
> > Really thanks in advance
> 
> > Matteo
> 
> 
> 
> 
> -- 
> Best regards,
>  Sergei
> 
> 
> 







More information about the users mailing list