ALT Linux Sisyphus discussions
 help / color / mirror / Atom feed
From: Serge Pavlovsky <pal@interexc.com>
To: ALT Linux Sisyphus discussion list <sisyphus@altlinux.ru>
Subject: Re: [sisyphus] Работа под 2.6.х с привязкой ко временным отметкам.
Date: Mon, 11 Oct 2004 03:27:16 +0300
Message-ID: <1097454436.2793.0.camel@underdark.interexc.com> (raw)
In-Reply-To: <200410081748.07275.serpiph@nikiet.ru>

It is not safe to call mutex functions from a signal handler.  In
particular, calling `pthread_mutex_lock' or `pthread_mutex_unlock' from
a signal handler may deadlock the calling thread.

On Птн, 2004-10-08 at 17:48 +0400, Epiphanov Sergei wrote:
> Есть программа, которую решил привязать к таймеру для работы в реальном 
> времени. Принцип простой: поставил обработку setitimer на запуск SIG_ALARM 
> с шагом 10 мсек.
> 
> #define _XOPEN_SOURCE 600
> #define _GNU_SOURCE
> #include <sys/time.h>
> #include <signal.h>
> #include <stdio.h>
> #include <pthread.h>
> 
> 
> 
> volatile int nextnum=0;
> volatile pthread_mutex_t fastmutex;
> 
> void alarmsig(int i){
>     pthread_mutex_lock( &fastmutex );
>     nextnum++;
>     pthread_mutex_unlock( &fastmutex );
> }
> 
> static struct sigaction oldsig;
> 
> /*type<0.5 - drop timer
>   type>0.5 - set timer*/
> void settimer_(float *type, float *step){
>     long int sec = *step;
>     long int usec = (*step-sec)*1e6;
>     struct itimerval tv,old;
>     struct sigaction newsig,temp;
>     pthread_mutexattr_t attr;
>     printf("sec=%ld usec=%ld\n",sec,usec);
>     if( *type>0.5 ){
>  pthread_mutexattr_init( &attr );
>  pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_FAST_NP );
>  pthread_mutex_init( &fastmutex, &attr );
>  pthread_mutexattr_destroy( &attr );
>  tv.it_interval.tv_sec = sec;
>  tv.it_interval.tv_usec = usec;
>  tv.it_value.tv_sec = sec;
>  tv.it_value.tv_usec = usec;
>  nextnum = 0;
>  newsig.sa_handler = alarmsig;
>  newsig.sa_flags = SA_NOMASK;
>  sigaction( SIGALRM, &newsig, &oldsig );
>  setitimer( ITIMER_REAL, &tv, &old );
>     } else{
>  tv.it_interval.tv_sec = 0;
>  tv.it_interval.tv_usec = 0;
>  tv.it_value.tv_sec = 0;
>  tv.it_value.tv_usec = 0;
>  setitimer( ITIMER_REAL, &tv, &old );
>  nextnum = 0;
>  sigaction( SIGALRM, &oldsig, &temp );
>  pthread_mutex_destroy( &fastmutex );
>     }
>     
> }
> 
> void waittime_( float *err ){
>     int cur = nextnum;
>     if( cur>1 ){
>  *err = cur;
>  return;
>     }
>     while( !cur ){
>  pthread_mutex_lock( &fastmutex );
>  cur = nextnum;
>  pthread_mutex_unlock( &fastmutex );
>     }
>     *err = 0;
>     pthread_mutex_lock( &fastmutex );
>     nextnum = 0;
>     pthread_mutex_unlock( &fastmutex );
>     return;
> }
> 
> Затем:
> 1)t=0
> 2)в цикле:
> а) основная программа
> б) t=t+10мсек
> в) waittime_(err)
> г) завершение цикла при t>=100сек.
> 
> Так вот, при таком раскладе на ядре 2.6.8-std-smp-alt9 программа работает 
> 110сек (+10%). И этот расклад не зависит от шага (10мсек, 100мсек, 1сек). 
> На ядре 2.4.26-std-up-alt6 эта же программа без пересборки работает точно 
> 100 сек. Что это может быть?
> 
> _______________________________________________
> Sisyphus mailing list
> Sisyphus@altlinux.ru
> https://lists.altlinux.ru/mailman/listinfo/sisyphus
> Scanned by evaluation version of Dr.Web antivirus Daemon 
> http://drweb.ru/unix/



  reply	other threads:[~2004-10-11  0:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-08 13:48 Epiphanov Sergei
2004-10-11  0:27 ` Serge Pavlovsky [this message]
2004-10-11  7:42   ` Epiphanov Sergei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1097454436.2793.0.camel@underdark.interexc.com \
    --to=pal@interexc.com \
    --cc=sisyphus@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Sisyphus discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
		sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
	public-inbox-index sisyphus

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.sisyphus


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git