To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2218
2217  |  2219
Subject: 
Re: threads - bug in the firmware?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 17 Jan 2002 17:54:39 GMT
Viewed: 
1724 times
  
Hi Mike,

your problem is not because of an error in legOS. But what you do is that
you start your subroutines and then you leave main()! Leaving main means
that all your allocated memory is freed. The following will do the job:

------------------ cut here --------------------------------------------

#include <conio.h>      // console
#include <unistd.h>     // UNIX std for timers and task management
#include <dkey.h>       // to allow user input, doh

pid_t pid1;
pid_t pid2;
pid_t pid3;

int bumper_task (int argc, char *argv[]);
int left_task (int argc, char *argv[]);
int right_task (int argc, char *argv[]);

wakeup_t bumper_hit (wakeup_t data);
wakeup_t key_hit (wakeup_t data);

void key (int data1, int data2);

int main(int argc, char *argv[])
{
   pid1 = execi (&bumper_task, 0, NULL, PRIO_NORMAL+4, DEFAULT_STACK_SIZE);
   pid2 = execi (&left_task,   0, NULL, PRIO_NORMAL+2, DEFAULT_STACK_SIZE);
   pid3 = execi (&right_task,  0, NULL, PRIO_NORMAL,   DEFAULT_STACK_SIZE);
   while( 1 );     // <<<<<<<<<<<<< this is crucial!
   return 0;
}

wakeup_t bumper_hit(wakeup_t data)
{
   return dkey_pressed( KEY_PRGM );
}

int bumper_task (int argc, char *argv[])
{
   while (1) {
      wait_event (&bumper_hit, 0);
      msleep(250);
      cputs ("ouch");
      kill(pid2);
      kill (pid3);
      cputs ("dead");
      msleep (1000);
//********** GETS THIS FAR******************

      pid2 = execi( &left_task, 0, NULL, PRIO_NORMAL+2, DEFAULT_STACK_SIZE);
      pid3 = execi (&right_task, 0, NULL, PRIO_NORMAL,  DEFAULT_STACK_SIZE);
      cputs( "finis" );
   }
   return 0;
}       // end of bumper_task ()

int left_task (int argc, char *argv[])
{
int k = 0;

   for (k = 50; k < 255; k++) {
      msleep (200);
   }

   return 0;
}

int right_task(int argc, char *argv[])
{
int k = 0;

   for (k = 50; k < 255; k++) {
      lcd_int (k);
      msleep (200);
   }
   return 0;
}

// ************* TEMP DEBUG CODE *************
void key (int data1, int data2)
{
   cputs ("key");
   wait_event (&key_hit, 0);
   lcd_int(data1);
   msleep (1000);
   cputw (data2);
   msleep (1000);
}

wakeup_t key_hit (wakeup_t data)
{
   return dkey_pressed (KEY_VIEW);
}



Message has 3 Replies:
  Re: threads - bug in the firmware?
 
;-) That worked a treat, thanks Michael. (thanks for the other little corrections in the code too). mike (...) Mike, (...) your subroutines and then you leave main()! Leaving main means (...) memory is freed. The following will do the job: (...) (...) (22 years ago, 17-Jan-02, to lugnet.robotics.rcx.legos)
  Re: threads - bug in the firmware?
 
(...) Note also since bumper_task() is an infinite loop, and you never use pid1, you could save one thread by doing this: int main(int argc, char *argv[]) { pid2 = execi (&left_task, 0, NULL, PRIO_NORMAL+2, DEFAULT_STACK_SIZE); pid3 = execi (...) (22 years ago, 17-Jan-02, to lugnet.robotics.rcx.legos)
  Re: threads - bug in the firmware?
 
(...) I would strongly suggest changing this to while(1) msleep(bignumber);. Otherwise you're hogging the processor doing nothing important, which could do bad things to any compute-intensive tasks you may have going. It'll also use slightly less (...) (22 years ago, 18-Jan-02, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: threads - bug in the firmware?
 
Hi again I have now totally stripped down my code to a minimum and I am still having problems with the code hanging up. I can see nowhere where there can be a fault. I am a long way from being an expert, but is it possible there is a bug in the (...) (22 years ago, 16-Jan-02, to lugnet.robotics.rcx.legos)

18 Messages in This Thread:





Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR