bug-glibc
[Top][All Lists]
Advanced

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

POSIX timer (SIGEV_THREAD), timer_create, timer_delete & glibc 2.2.5


From: Clemens Fuchslocher
Subject: POSIX timer (SIGEV_THREAD), timer_create, timer_delete & glibc 2.2.5
Date: Wed, 24 Apr 2002 23:03:27 +0200 (CEST)

hi,

I got some strange behavior when using POSIX timers (the SIGEV_THREAD
ones). When i repeatedly create and delete a timer i get the following
error: 'Resource temporarily unavailable'. I known that POSIX timers
are a limited system resource but i thought they could be reused after
a timer_delete call. It also seems to me that after a timer_delete the
corresponding thread (which is used for the timer) will stay alive.

If i use the SIGEV_SIGNAL notification scheme instead of the SIGEV_THREAD
one i could repeatedly start and stop as many timers as i want.


System:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
z:~$ uname -a
Linux foo 2.4.17 #1 Mon Feb 25 17:04:10 CET 2002 i686 unknown
z:~$ gcc --version
2.95.4
z:~$ /lib/libc.so.6
GNU C Library stable release version 2.2.5, by Roland McGrath et al.
[...]
Available extensions:
        GNU libio by Per Bothner
        crypt add-on version 2.1 by Michael Glad and others
        linuxthreads-0.9 by Xavier Leroy
        BIND-8.2.3-T5B
        libthread_db work sponsored by Alpha Processor Inc
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Report bugs using the `glibcbug' script to <address@hidden>.
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=


Here is an example that produces the error mentioned above:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
/* gcc -Wall -D_REENTRANT -D_POSIX_TIMERS timer.c -o timer -lrt */

#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include <unistd.h>
#include <pthread.h>

void start (void);
void stop (void);
void t (union sigval sigval);

int timer_nr;
timer_t timer;

int main (void)
{
    for (timer_nr = 0;; timer_nr++)
    {
        start ();
        sleep (4);
        stop ();
    }

    return EXIT_SUCCESS;
}

void start (void)
{
    struct itimerspec itimer = { { 1, 0 }, { 1, 0 } };
    struct sigevent sigev;

    memset (&sigev, 0, sizeof (struct sigevent));
    sigev.sigev_value.sival_int = timer_nr;
    sigev.sigev_notify = SIGEV_THREAD;
    sigev.sigev_notify_attributes = NULL;
    sigev.sigev_notify_function = t;

    if (timer_create (CLOCK_REALTIME, &sigev, &timer) < 0)
    {
        fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
        exit (errno);
    }

    if (timer_settime (timer, 0, &itimer, NULL) < 0)
    {
        fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
        exit (errno);
    }
}

void stop (void)
{
    if (timer_delete (timer) < 0)
    {
        fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
        exit (errno);
    }
}

void t (union sigval sigval)
{
    printf ("timer_nr=%02d  pid=%d  pthread_self=%ld\n",
            sigval.sival_int, getpid (), pthread_self ());
}
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=

'timer_create - create a per-process timer'
<http://www.opengroup.org/onlinepubs/007908799/xsh/timer_create.html>

'timer_delete - delete a per-process timer'
<http://www.opengroup.org/onlinepubs/007908799/xsh/timer_delete.html>

'timer_settime, timer_gettime, timer_getoverrun - per-process timers'
<http://www.opengroup.org/onlinepubs/007908799/xsh/timer_settime.html>


The above program generates the following output:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
z~$ gcc -Wall -D_REENTRANT -D_POSIX_TIMERS timer.c -o timer -lrt
z~$ ./timer
timer_nr=00  pid=21535  pthread_self=1026
timer_nr=00  pid=21535  pthread_self=1026
timer_nr=00  pid=21535  pthread_self=1026
timer_nr=01  pid=21535  pthread_self=1026
timer_nr=01  pid=21535  pthread_self=1026
timer_nr=01  pid=21535  pthread_self=1026
timer_nr=02  pid=21559  pthread_self=2051
timer_nr=02  pid=21559  pthread_self=2051
timer_nr=02  pid=21559  pthread_self=2051
timer_nr=03  pid=21559  pthread_self=2051
timer_nr=03  pid=21559  pthread_self=2051
timer_nr=03  pid=21559  pthread_self=2051
[...]
timer_nr=29  pid=21652  pthread_self=15376
timer_nr=29  pid=21652  pthread_self=15376
timer_nr=29  pid=21652  pthread_self=15376
timer_nr=30  pid=21654  pthread_self=16401
timer_nr=30  pid=21654  pthread_self=16401
timer_nr=30  pid=21654  pthread_self=16401
timer_nr=31  pid=21654  pthread_self=16401
timer_nr=31  pid=21654  pthread_self=16401
timer_nr=31  pid=21654  pthread_self=16401
timer: ../linuxthreads/sysdeps/pthread/timer_routines.c:570:
__timer_dealloc: Assertion `timer->refcount == 0' failed.
Aborted
z:~$
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=

On another system (glibc 2.2.4) it generates the following message:
 [45]: Resource temporarily unavailable


After 'timer_nr=31' the processtable looks like that:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
z~$ ps wuf | grep timer
z 21533  0.0  0.0 34320  648 pts/0   S   18:02   0:00 ./timer
z 21534  0.0  0.0 34320  648 pts/0   S   18:02   0:00  \_ ./timer
z 21535  0.0  0.0 34320  648 pts/0   S   18:02   0:00      \_ ./timer
z 21559  0.0  0.0 34320  648 pts/0   S   18:02   0:00      \_ ./timer
z 21567  0.0  0.0 34320  648 pts/0   S   18:02   0:00      \_ ./timer
z 21577  0.0  0.0 34320  648 pts/0   S   18:02   0:00      \_ ./timer
z 21578  0.0  0.0 34320  648 pts/0   S   18:02   0:00      \_ ./timer
z 21588  0.0  0.0 34320  648 pts/0   S   18:03   0:00      \_ ./timer
z 21591  0.0  0.0 34320  648 pts/0   S   18:03   0:00      \_ ./timer
z 21597  0.0  0.0 34320  648 pts/0   S   18:03   0:00      \_ ./timer
z 21598  0.0  0.0 34320  648 pts/0   S   18:03   0:00      \_ ./timer
z 21602  0.0  0.0 34320  648 pts/0   S   18:03   0:00      \_ ./timer
z 21605  0.0  0.0 34320  648 pts/0   S   18:03   0:00      \_ ./timer
z 21606  0.0  0.0 34320  648 pts/0   S   18:03   0:00      \_ ./timer
z 21615  0.0  0.0 34320  648 pts/0   S   18:04   0:00      \_ ./timer
z 21617  0.0  0.0 34320  648 pts/0   S   18:04   0:00      \_ ./timer
z 21652  0.0  0.0 34320  648 pts/0   S   18:04   0:00      \_ ./timer
z 21654  0.0  0.0 34320  648 pts/0   S   18:04   0:00      \_ ./timer
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=

I don't understand it.

:)
-- 




reply via email to

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