Cthreads and signal/ualarm problems

Cthreads and signal/ualarm problems

Post by Scott McIntos » Mon, 02 Jun 1997 04:00:00



Hello,

I'm having a very random problem trying to use ualarm to provide a timed
interrupt for a preemptive scheduler for some cthreads.  So far, I
can't even get the interrupt creation/handling happening reliably.
Sometimes it stalls.  Sometimes it gets past a couple of "ALARM"
printouts (the only action of the handler other than cthread_yield)
and then stalls.  Rarely it finishes.  Sometimes it dies with a
segmentation fault, sometimes right after printing ALARM.  I would
figure the first signal() command in init() would be all I'd need,
but if I put signal() all over the place, my program tends to finish
more often, but still not always.  I've looked all over the net and
my machine's man pages and find nothing to say what I've set up is
wrong.  The machine is running SunOS UNIX 4.1.3 on 4 hyperSPARCs.
All the man pages say SystemV, but I've been told the OS is BSD, which
is why I feel I only need one signal().  The program finishes just
fine if I comment out the ualarm command.

Any help is appreciated.  The current code is below.

--
Scott McIntosh

June 14th, come on June 14th...

/* include files */
#include <stdio.h>
#include <cthread.h>
#include <signal.h>

/* constants */
#define NUM_PROC         2
#define NUM_DATA         10

/* function prototypes */
void main(void);
void init(void);
void producer(int);
void consumer(int);
void handler(void);

/*****************************************************/

void main(void)
{
   cthread_init(NUM_PROC, init);

Quote:}

/*****************************************************/

void init(void)
{
   int         i;

   signal(SIGALRM, handler);

   /* create the producers and consumers */
   aprintf("Create children\n");
   signal(SIGALRM, handler);
   for (i=0; i<NUM_PROC; i++) {
   signal(SIGALRM, handler);
      cthread_detach(cthread_fork( (any_t)producer, (any_t)(10*i+1),
i));
   signal(SIGALRM, handler);
      cthread_detach(cthread_fork( (any_t)producer, (any_t)(10*i+2),
i));
   signal(SIGALRM, handler);
      cthread_detach(cthread_fork( (any_t)consumer, (any_t)(10*i+1),
i));
   signal(SIGALRM, handler);
      cthread_detach(cthread_fork( (any_t)consumer, (any_t)(10*i+2),
i));
   }
   aprintf("Start Alarm\n");
   signal(SIGALRM, handler);
   ualarm(1, 1000);
   signal(SIGALRM, handler);
   /* wait for them to finish, then end */
   aprintf("Go into barrier\n");
   barrier();
   signal(SIGALRM, handler);

Quote:}

/*****************************************************/

void producer(int id)
{
   int i,j;

   signal(SIGALRM, handler);
   aprintf("Producer %d is alive\n", id);
   signal(SIGALRM, handler);
   j = 0;
   signal(SIGALRM, handler);
   /* produce NUM_DATA tax entries */
   while (j < NUM_DATA) {
   signal(SIGALRM, handler);
      j = j + 1;
   signal(SIGALRM, handler);
      aprintf("hellop%d\n",id);
   }
   signal(SIGALRM, handler);
   aprintf ("producer %d exiting\n", id);

Quote:}

/*****************************************************/

void consumer(int id)
{
   int i,j,tax;

   signal(SIGALRM, handler);
   aprintf("Consumer %d is alive\n", id);
   signal(SIGALRM, handler);
   j = 0;
   /* read NUM_DATA tax entries */
   while (j < NUM_DATA) {
   signal(SIGALRM, handler);
      j = j + 1;
   signal(SIGALRM, handler);
      aprintf("helloc%d\n",id);
   }
   signal(SIGALRM, handler);
   aprintf ("consumer %d exiting.\n", id);

Quote:}

/*****************************************************/

void handler(void)
{
   signal(SIGALRM, handler);
   aprintf("ALARM\n");
   cthread_yield();
   signal(SIGALRM, handler);

Quote:}

 
 
 

Cthreads and signal/ualarm problems

Post by Andrew Giert » Mon, 02 Jun 1997 04:00:00


 Scott> void handler(void)
 Scott> {
 Scott>    signal(SIGALRM, handler);

Forget signal() was ever invented. Only use sigaction().

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>