bug-hurd
[Top][All Lists]
Advanced

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

some general and some not so general programming questions


From: Frank Saar
Subject: some general and some not so general programming questions
Date: Wed, 11 Dec 2002 02:33:47 -0800

Hello,
I have several questions of how things are to be done in hurd:
1. Is there anything like events ?
    I wonder how to implement an event mechanism without using volatile
variables and continous testing of those with while();
2. How to implement a timer routine
    I played with signal(SIGALRM,..),setitimer but it didnt work as
expected.
    in the multithreaded case the program exits with the output "Alarm
clock", but not by me:
volatile int i=0;

void handler(int sig) {
        printf("**************************************\n");
        fflush(stdout);
        i=1;
}

any_t test_routine1(any_t arg)
{
        struct itimerval real;
        real.it_interval.tv_usec=1;
        real.it_interval.tv_sec=0;
        real.it_value.tv_usec=1;
        real.it_value.tv_sec=0;

        signal(SIGALRM,handler);

        setitimer(ITIMER_REAL,&real,0);
        return (0);
};

int main() {
        cthread_detach (cthread_fork (test_routine1, (any_t*) &i));
        cthread_detach (cthread_fork (test_routine1, (any_t*) &i));
        while (!i);
        return (0);
}

In the single threaded case (routine1 is called directly) SIGALRM is
continously triggered and the result is an endless output of "****"-lines. I
normally would expect that only one line is printed. Can anyone explain this
behaviour ?

3. Why do I get different results ?:
    compiling the above example with gcc -o test
test.c -lports -lthreads -lfshelp and runing it results in the thread
test_routine1 not being executed. If I compile it with gcc -o test test.c
$(HURD_SRC)/libports/libports.a  $(HURD_SRC)/libthreads/libthreads.a
$(HURD_SRC)/libfshelp/libfshelp.a everythings fine.

4. BTW. I tried to compile libpthread. It resulted in the error
"/include/libc-symbol.h needed by lockfile.d".
    Checking the makefile revealed that the line -i macros
$(srcdir)/include/libc-symbols.h was responsible for this. So I thought that
srcdir might not be defined. But in $(HURD_BASE)/Make_conf does define it if
not already defined. Setting srcdir explicitly seems to solve it.
Nevertheless compiling a modfied example test-1.c doesnt seem to result in
the creation of a thread because there was no output
I compiled it with:
gcc test-1.c -o test1 ../libpthread/libpthread.a ../libports/libports.a
../libihash/libihash.a -I../libpthread/include/ -I../libpthread/sysdeps/gene
ric/ -I../libpthread/sysdeps/i386/ -D__USE_EXTERN_INLINES
I also attached gdb to it and set a breakpoint on foo. no result:i.e. no
break at foo.
Is there anything I have to add ?

void *foo (void *arg)
{
printf("in foo\n");
fflush(stdout);
  pthread_mutex_t *mutex = arg;
  pthread_mutex_lock (mutex);
  pthread_mutex_unlock (mutex);
  return mutex;
}

int
main (int argc, char **argv)
{
  int i;
  error_t err;
  pthread_t tid;
  pthread_mutex_t mutex;

    {
      mutex = PTHREAD_MUTEX_INITIALIZER;
      pthread_mutex_lock (&mutex);
      err = pthread_create (&tid, 0, foo, &mutex);
      if (err)
error (1, err, "pthread_create");
      sched_yield ();
    }

  return 0;
}



Frank




reply via email to

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