bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with Linux CommonC++ Thread Class scheduling


From: Ian Campbell
Subject: Re: Problems with Linux CommonC++ Thread Class scheduling
Date: Fri, 22 Jun 2001 15:37:47 +0100 (BST)

The code below that gets the priority and the policy of the creating
process and uses that to create the new thread so that should be ok. Not
sure what happens in other implementations though.

Ian

Ian Campbell
Band-X
t: +44 (0) 207 932 8846
f: +44 (0) 207 932 8800
e: address@hidden

On Fri, 22 Jun 2001, David Sugar wrote:

> I have thought about this more, and I think the most correct solution is that
> the setinherit should be called, but only when pri = 0, which indicates you do
> want it scheduled the same as the parent, or in systems which do not allow
> setting and changing of scheduler priorities anyway.  So I will do a more
> specific implimentation of this.
>
> David
>
> Ian Campbell wrote:
>
> > Hello All,
> >         I have been experimenting with the CommonC++ Thread class on Linux
> > using the realtime pthread scheduler (either SCHED_RR or SCHED_FIFO) and
> > found it doesn't work properly in the 1.4.3 release. This fault means that
> > you can't give seperate threads a different priority from the creating
> > main process. This is caused by a call to pthread_attr_setinheritsched()
> > which according to the man page means that the priority and policy for
> > thread scheduler must be inherited from the creating thread. As such any
> > subsequent calls to pthread_attr_setschedpolicy() and
> > pthread_attr_setschedparam() will have no effect. Anyway the patch at the
> > end of this email should fixeth the problem.
> >
> > Cheers,
> >
> > Ian Campbell
> > Band-X
> > t: +44 (0) 207 932 8846
> > f: +44 (0) 207 932 8800
> > e: address@hidden
> >
> > diff -u -r CommonC++-1.4.3/posix/thread.cpp
> > CommonC++-1.4.3-sched.patch/posix/thread.cpp
> > --- CommonC++-1.4.3/posix/thread.cpp        Thu May 31 08:30:51 2001
> > +++ CommonC++-1.4.3-sched.patch/posix/thread.cpp    Thu Jun 21
> > 12:41:08 2001
> > @@ -1,23 +1,23 @@
> >  // Copyright (C) 1999-2001 Open Source Telecom Corporation.
> > -//
> > +//
> >  // This program is free software; you can redistribute it and/or modify
> >  // it under the terms of the GNU General Public License as published by
> >  // the Free Software Foundation; either version 2 of the License, or
> >  // (at your option) any later version.
> > -//
> > +//
> >  // This program is distributed in the hope that it will be useful,
> >  // but WITHOUT ANY WARRANTY; without even the implied warranty of
> >  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >  // GNU General Public License for more details.
> > -//
> > +//
> >  // You should have received a copy of the GNU General Public License
> > -// along with this program; if not, write to the Free Software
> > +// along with this program; if not, write to the Free Software
> >  // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
> > USA.
> > -//
> > -// As a special exception to the GNU General Public License, permission
> > is
> > -// granted for additional uses of the text contained in its release
> > +//
> > +// As a special exception to the GNU General Public License, permission
> > is
> > +// granted for additional uses of the text contained in its release
> >  // of Common C++.
> > -//
> > +//
> >  // The exception is that, if you link the Common C++ library with other
> >  // files to produce an executable, this does not by itself cause the
> >  // resulting executable to be covered by the GNU General Public License.
> > @@ -27,16 +27,16 @@
> >  // This exception does not however invalidate any other reasons why
> >  // the executable file might be covered by the GNU General Public
> > License.
> >  //
> > -// This exception applies only to the code released under the
> > +// This exception applies only to the code released under the
> >  // name Common C++.  If you copy code from other releases into a copy of
> >  // Common C++, as the General Public License permits, the exception does
> >  // not apply to the code that you add in this way.  To avoid misleading
> >  // anyone as to the status of such modified files, you must delete
> >  // this exception notice from them.
> > -//
> > +//
> >  // If you write modifications of your own for Common C++, it is your
> > choice
> >  // whether to permit this exception to apply to your modifications.
> > -// If you do not wish that, delete this exception notice.
> > +// If you do not wish that, delete this exception notice.
> >
> >  #include "config.h"
> >  #include "macros.h"
> > @@ -137,7 +137,7 @@
> >             sigaction(SIGPOLL, &act, NULL);
> >  #else
> >             sigaction(SIGIO, &act, NULL);
> > -#endif
> > +#endif
> >
> >  #ifndef    _SIG_THREAD_STOPCONT
> >  #ifndef    _THR_SUNOS5
> > @@ -161,11 +161,11 @@
> >             sigaddset(&act.sa_mask, SIGPIPE);
> >
> >             sigaction(_SIG_THREAD_CANCEL, &act, NULL);
> > -#endif
> > +#endif
> >             _main = this;
> >             }
> >     _self.setKey(this);
> > -}
> > +}
> >
> >  Thread::Thread(Semaphore *start, int pri, size_t stack)
> >  {
> > @@ -176,7 +176,7 @@
> >
> >     pthread_attr_init(&_attr);
> >     pthread_attr_setdetachstate(&_attr, PTHREAD_CREATE_JOINABLE);
> > -   pthread_attr_setinheritsched(&_attr, PTHREAD_INHERIT_SCHED);
> > +
> >
> >  #ifdef     PTHREAD_STACK_MIN
> >     if(pthread_attr_setstacksize(&_attr, stack <= PTHREAD_STACK_MIN ?
> > PTHREAD_STACK_MIN : stack))
> > @@ -192,7 +192,7 @@
> >  #endif
> >
> >  #ifndef    __FreeBSD__
> > -#ifdef     _POSIX_THREAD_PRIORITY_SCHEDULING
> > +#ifdef     _POSIX_THREAD_PRIORITY_SCHEDULING
> >     if(pri)
> >     {
> >             struct sched_param sched;
> > @@ -220,8 +220,9 @@
> >                     pri = sched_get_priority_min(policy);
> >
> >             sched.sched_priority = pri;
> > +           pthread_attr_setschedpolicy(&_attr, policy);
> >             pthread_attr_setschedparam(&_attr, &sched);
> > -   }
> > +   }
> >  #endif
> >  #endif
> >
> > @@ -289,7 +290,7 @@
> >     {
> >             pthread_detach(_tid);
> >             if(_start)
> > -           {
> > +           {
> >                     _start->Post();
> >                     return 0;
> >             }
> > @@ -351,7 +352,7 @@
> >                     Thread::_timer->OnTimer();
> >             }
> >             else
> > -#endif
> > +#endif
> >                 if(th)
> >                     th->OnTimer();
> >             break;
> > @@ -386,7 +387,7 @@
> >
> >     if(!setjmp(th->_env))
> >     {
> > -           th->Initial();
> > +           th->Initial();
> >             if(th->getCancel() == THREAD_CANCEL_INITIAL)
> >                     th->setCancel(THREAD_CANCEL_DEFAULT);
> >
> > @@ -411,7 +412,7 @@
> >
> >  #ifdef     HAVE_SETITIMER
> >     struct itimerval itimer;
> > -
> > +
> >     memset(&itimer, 0, sizeof(itimer));
> >     itimer.it_value.tv_usec = (timer * 1000) % 1000000;
> >     itimer.it_value.tv_sec = timer / 1000;
> > @@ -419,7 +420,7 @@
> >     timer /= 1000;
> >  #endif
> >
> > -#ifndef    _SIG_THREAD_ALARM
> > +#ifndef    _SIG_THREAD_ALARM
> >     _arm;
> >     _timer = this;
> >  #endif
> > @@ -432,7 +433,7 @@
> >  #else
> >     alarm(timer);
> >  #endif
> > -}
> > +}
> >
> >  timeout_t Thread::getTimer(void)
> >  {
> > @@ -491,7 +492,7 @@
> >  #else
> >     sigwait(&mask, &signo);
> >  #endif
> > -}
> > +}
> >
> >  void       Thread::setSuspend(thread_suspend_t mode)
> >  {
> > @@ -518,7 +519,7 @@
> >
> >     sigemptyset(&mask);
> >     sigaddset(&mask, _SIG_THREAD_CANCEL);
> > -
> > +
> >     switch(mode)
> >     {
> >     case THREAD_CANCEL_IMMEDIATE:
> > @@ -545,7 +546,7 @@
> >             pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
> >     else
> >             pthread_sigmask(SIG_BLOCK, &sigs, NULL);
> > -}
> > +}
> >
> >  void       Thread::setCancel(thread_cancel_t mode)
> >  {
> > @@ -580,7 +581,7 @@
> >     sigemptyset(&cancel);
> >     sigaddset(&cancel, _SIG_THREAD_CANCEL);
> >
> > -   if(_cancel != THREAD_CANCEL_DISABLED &&
> > +   if(_cancel != THREAD_CANCEL_DISABLED &&
> >        _cancel != THREAD_CANCEL_INITIAL)
> >             pthread_sigmask(SIG_UNBLOCK, &cancel, &old);
> >  #else
> > @@ -600,28 +601,28 @@
> >  {
> >  #ifdef  _SIG_THREAD_CANCEL
> >          sigset_t cancel, old;
> > -
> > +
> >          sigemptyset(&cancel);
> >          sigaddset(&cancel, _SIG_THREAD_CANCEL);
> > -
> > +
> >          if(_cancel != THREAD_CANCEL_DISABLED &&
> >             _cancel != THREAD_CANCEL_INITIAL)
> >                  pthread_sigmask(SIG_UNBLOCK, &cancel, &old);
> >  #else
> >          pthread_testcancel();
> >  #endif
> > -
> > +
> >  #ifdef  _SIG_THREAD_CANCEL
> >          if(_cancel != THREAD_CANCEL_DISABLED)
> >                  pthread_sigmask(SIG_SETMASK, &old, NULL);
> >  #endif
> > -}
> > +}
> >
> >
> >  void siginstall(int signo)
> >  {
> >     struct sigaction act;
> > -
> > +
> >     act.sa_handler = (signalexec_t)&sigHandler;
> >     sigemptyset(&act.sa_mask);
> >
> >
> >
> >
> > _______________________________________________
> > Bug-commoncpp mailing list
> > address@hidden
> > http://mail.gnu.org/mailman/listinfo/bug-commoncpp
>
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]