[eduos] Re: psEduOS

  • From: Frank Cornelis <Frank.Cornelis@xxxxxxxxx>
  • To: Alejandro Palacio <alpawi@xxxxxxxxxxx>
  • Date: Fri, 8 Jun 2001 21:13:48 +0200 (MEST)


> 1) If I would want to see the current tasks (like Linux 'ps' command),
> where I must see....in
> Descriptor entries [NO_GDT_ENTRIES]
> or in
> IDT.entries [IDT_ENTRIES] ????
> How could I acces it?

mmm...The best to do for getting information on all registered tasks is to
run through current_task in task.c using the next field of the TaskEntry
structure (in task.h). But of course, current_field is a static variable
in task.c, so you won't be able to access it from within main.c.
Be careful, making this variable non-static (so public) is very
dangerous. Because, when you run through the task list manually using next
pointers and there occurs a task switch, and one of the tasks does
something that alters the task list, you could end up having an illegal
TaskEntry pointer. Still following?
So, the best/easiest thing to do is to add next function declarations to
task.h:

        TaskEntry* get_current_task_pointer ();
        void unlock_current_task_pointer ();

And put in task.c:

        TaskEntry* get_current_task_pointer () {
                clearInterruptFlag ();
                return current_task;
        }

        void unlock_current_task_pointer () {
                setInterruptFlag ();
        }

Now you can use these functions in main.c like this:

        TaskEntry* current_task = get_current_task_pointer ();
        ... run through current_task ...
        ... but hurry, because so task switches can occur since
        the interrupt flag has been cleared ...
        unlock_current_task_pointer (); /* DON'T FORGET THIS */
        /* the system can switch tasks again ... */

> 2) In a function, some times there is a concurrency problem, but I'm not
> sure in which part of the function I must locate the critical section
> for avoid problems???
> If I call the next function in a task( for example):
>
> I have:
>
> void print_fibo(int n);
>
> int fibo(int n);
>
> and I register the task:
>
> task_id = registerKernelTask((dword)print_fibo,7);
>
> and
> void print_fibo(int n)
> {
> printf ("%d", fibo(n));
> }
> int fibo (int n)
> {
> if (n==0 || n==1)
> return n;
> else
> return fibo (n-1) + fibo (n-2);
> }
> Where should be the critical section?????

In the example you are giving, there is no need for a critical section,
since there is no part that has something critical.
For an example of critical section stuff, look at main.c in EduOS version
0.1.12 (can also be downloaded from the EduOS site). That main.c also
contains examples of how to use kernelLock and kernelUnlock.

When having more questions, feel free to ask.

Frank.



----------------------------------------
The EduOS home page can be found at:
http://studwww.rug.ac.be/~fcorneli/eduos
----------------------------------------

Other related posts:

  • » [eduos] Re: psEduOS