pthread

Pattara Kiatisevi pkiatisevi at student.ei.uni-stuttgart.de
Thu Mar 7 15:45:38 UTC 2002


The default &_POSIX_Threads_Default_attributes looks correct:

(gdb) print *attr
$10 = {is_initialized = 1, stackaddr = 0x0, stacksize = 8192,
contentionscope = 0, inheritsched = 1,
  schedpolicy = 1, schedparam = {sched_priority = 2, ss_low_priority = 0,
ss_replenish_period = {
      tv_sec = 0, tv_nsec = 0}, ss_initial_budget = {tv_sec = 0, tv_nsec =
0}},

But then from this code in pthread_create.c:

---------------------------------------------------------------------
  switch ( the_attr->inheritsched ) {
    case PTHREAD_INHERIT_SCHED:
      api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
      schedpolicy = api->schedpolicy;
      schedparam  = api->schedparam;
      break;

    case PTHREAD_EXPLICIT_SCHED:
      schedpolicy = the_attr->schedpolicy;
      schedparam  = the_attr->schedparam;
      break;

---------------------------------------------------------------------
As the_attr->inheritsched = 1 --> api is pointed to
_Thread_Executing->API_Extensions[ THREAD_API_POSIX ];

(gdb) print *(pthread_attr_t *) _Thread_Executing->API_Extensions[
THREAD_API_POSIX ]
$13 = {is_initialized = 1024, stackaddr = 0x4005cf98, stacksize = 0,
contentionscope = 1077805608,
  inheritsched = 1077802744, schedpolicy = 1074041268, schedparam =
{sched_priority = 1074029292,
    ss_low_priority = 8192, ss_replenish_period = {tv_sec = 1077802760,
tv_nsec = 1074108524},
    ss_initial_budget = {tv_sec = 260, tv_nsec = 13}},
cputime_clock_allowed = 196,
  detachstate = 1074035620}

This above one looks not so good. Do you think that my code overwrites it
somehow? Hmm, I will try to have my code purified and see..

Thanks,
Pattara


On Thu, 7 Mar 2002, Joel Sherrill wrote:

>
>
> Pattara Kiatisevi wrote:
> >
> > Thank you for the answer.
> >
> > Seems that the "default" priority is set something weird?
>
> Look at the default structure before you run very far.  I
> suspect you are overwriting it.
>
> I have (quickly) doublechecked the pre-initialized structure
> for default attributes in pthread.c and don't see where
> it doesn't match field for field and is initialized
> correctly.  So that leads me to believe it is corrupted
> by execution.
>
> > -----------------------------------------------------------------
> > 285         task_ret = pthread_create(&audioPlay, NULL, (void *)
> > playAudioTask, (void *) &taskparameter);(gdb) s
> > pthread_create (thread=0x403f7d70, attr=0x0, start_routine=0x4000187c
> > <playAudioTask>, arg=0x403f7d68)
> >     at ../../../../../../../c/src/exec/posix/src/pthreadcreate.c:41
> > 41        the_attr = (attr) ? attr : &_POSIX_Threads_Default_attributes;
> > (gdb) n
> > 43        if ( !the_attr->is_initialized )
> > (gdb) print the_attr
> > $1 = (pthread_attr_t *) 0x4005dc80
> > (gdb) n
> > 51        if ( the_attr->stackaddr && !_Stack_Is_enough(
> > the_attr->stacksize ) )
> > (gdb) n
> > 70            api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
> > (gdb) n
> > 72            schedparam  = api->schedparam;
> > (gdb) n
> > 71            schedpolicy = api->schedpolicy;
> > (gdb) n
> > 72            schedparam  = api->schedparam;
> > (gdb)
> > 73            break;
> > (gdb)
> > 89        if ( the_attr->contentionscope != PTHREAD_SCOPE_PROCESS )
> > (gdb)
> > 20        return (boolean) (priority >= 1 && priority <= 254);
> > (gdb)
> > 96        if ( !_POSIX_Priority_Is_valid( schedparam.sched_priority ) )
> > (gdb)
> > 235         return EINVAL;
> > (gdb) print schedparam
> > $2 = {sched_priority = 1073764644, ss_low_priority = 8217,
> > ss_replenish_period = {tv_sec = 1077899424,
> >     tv_nsec = 1074035684}, ss_initial_budget = {tv_sec = 0, tv_nsec = 0}}
> > (gdb) print schedparam.sched_priority
> > $3 = 1073764644
> > (gdb) n
> > 247     }
> > (gdb)
> > Init (ignored=0) at player.c:286
> > 286         if (task_ret) {
> > (gdb) print task_ret
> > $4 = 22
> >
> > Pattara
> > --
> > Please avoid sending me Word or PowerPoint attachments.
> > See http://www.fsf.org/philosophy/no-word-attachments.html
> > ----------------------------------------------------------------------
> > Ott Pattara Kiatisevi                              T L W G
> > M.Sc. INFOTECH Student, Stuttgart, Germany      http://linux.thai.net/
> > ----------------------------------------------------------------------
> >
> > On Thu, 7 Mar 2002, Joel Sherrill wrote:
> >
> > >
> > >
> > > Pattara Kiatisevi wrote:
> > > >
> > > > Hi,
> > > >
> > > > I'm writing a pthread program. In the header I have:
> > > >
> > > > #define CONFIGURE_MAXIMUM_POSIX_THREADS 5
> > > > #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 5
> > > > #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 5
> > > >
> > > > Then in Init() I have sth. like:n
> > > >
> > > >  {
> > > >     int task_ret;
> > > >     task_ret = pthread_create(&audioPlay, NULL, (void *) playAudioTask,
> > > > (void *) &taskparameter);
> > > >     if (task_ret) {
> > > >       perror("pthread_create: playAudioTask");
> > > >       exit(EXIT_FAILURE);
> > > >     }
> > > >   }
> > > >
> > > > The program exited with task_ret = 22. Anybody has the idea what this "22"
> > > > means? Do I have to set any #define more in order to have pthread function
> > > > worked?
> > >
> > >
> > > You probably want to use strerror or perror on the exit paths.  But
> > > see /opt/rtems/CPU-rtems/include/sys/errno.h for the mapping.  This
> > > is EINVAL.  Unfortunately, that is a catch all error in in POSIX.
> > > The only real error it doesn't cover is not configuring enough
> > > pthreads.  I hate to suggest this but you would be better off
> > > tracing into the call or at least reading the pthreadcreate.c
> > > source and see if something rings a bell.   Here is the URL
> > > for the man page which lists the conditions for EINVAL:
> > >
> > > http://www.oarcorp.com/rtemsdoc-4.5.1-pre3/rtemsdoc/html/posix_users/posix_users00344.html
> > >
> > > > Thank you very much,
> > >
> > > POSIX makes figuring out what is wrong with a call tough.
> > > I don't see anything obvious myself.
> > >
> > > > Pattara
> > > >
> > > > --
> > > > Please avoid sending me Word or PowerPoint attachments.
> > > > See http://www.fsf.org/philosophy/no-word-attachments.html
> > > > ----------------------------------------------------------------------
> > > > Ott Pattara Kiatisevi                              T L W G
> > > > M.Sc. INFOTECH Student, Stuttgart, Germany      http://linux.thai.net/
> > > > ----------------------------------------------------------------------
> > >
> > > --
> > > Joel Sherrill, Ph.D.             Director of Research & Development
> > > joel at OARcorp.com                 On-Line Applications Research
> > > Ask me about RTEMS: a free RTOS  Huntsville AL 35805
> > > Support Available                (256) 722-9985
> > >
> > >
>
> --
> Joel Sherrill, Ph.D.             Director of Research & Development
> joel at OARcorp.com                 On-Line Applications Research
> Ask me about RTEMS: a free RTOS  Huntsville AL 35805
> Support Available                (256) 722-9985
>
>




More information about the users mailing list