Reply by mjames_doveridge June 20, 20092009-06-20
>
> The source code of the CTL is not available to me. Can't know how it switches task. But I believe it did that on every cycle of the task's infinite loop, then check the highest priority to run, if no highest priority then run the next same priority task.

Nearly

There is no 'infinite loop'. The OS is entered from interrupts, either 'real' interrupts generated by hardware, or interrupt-like OS calls from the running thread. It is only at these times that task-switching can occur based on the priorities of ready threads. If there are no hardware interrupts, and the running thread does not make system calls, there will be no task switching since the OS is not entered.

One hardware interrupt that is, IME, always provided is a periodic timer, enabling the use of timeouts on waits and allowing a fair allocation of CPU when there is more than one highest-priority thread ready, (a state you should aim to keep to a minimum).

Just because a timer interrupt is always provided, it is not absolutly essential - it is quite possible to run some multitasking systems without a timer interrupt, though not having timeouts on waits would be a big problem for most apps.

Rgds,
Martin

An Engineer's Guide to the LPC2100 Series

Reply by Jim Norton June 19, 20092009-06-19
Quoting sanylcs :

>
> Thank you everyone. i guess i am missing something on the memory
> management. dynamic memory quite new for me, i have no idea what is
> that ctl_libc_mutex use for, all the while i just know malloc, free,
> calloc and heap. Never thought there is more things need to be
> setup when implementing it into OS. That's y i try the simple steps
> before go into deeper. at least i know it is possible to use them
> with CTL with ctl_libc_mutex mayb.

A mutex is used to serialize access to shared resources in a
multi-tasking system. Here is a link that will get you started in your
quest to understanding some of the concepts involved:
http://en.wikipedia.org/wiki/Mutual_exclusion

----------------------------------
Jim Norton

"Wrong is wrong even if everyone is doing it; Right is right even if no
one is doing it." -St. Augustine.
-----------------------------------
Reply by phil...@comvurgent.com June 19, 20092009-06-19
U

Sent using BlackBerry from Orange



-----Original Message-----

From: "sanylcs"



Date: Fri, 19 Jun 2009 09:26:45

To:

Subject: [lpc2000] Re: CTL tasking library with malloc/calloc





--- In l..., "Paul Curtis" wrote:

>

> Hi,

>

> > The source code of the CTL is not available to me. Can't know how it

> > switches task. But I believe it did that on every cycle of the task's

> > infinite loop, then check the highest priority to run, if no highest

> > priority then run the next same priority task.

>

> Try helping yourself. The source of CTL is shipped with CrossWorks.

>

> $(StudioDir)/ctl/source

>

> But then I guess if you can't find that and don't know much about an RTOS or

> memory management, the source will be beyond your capability.

>

> --

> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk

> CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!

>



OH, thank you. I found the source. my bad never notice that b4 this. was using the library .a file all the time.



but well, as u expected, still wondering what happening to cause the task A run less frequent than task B after using malloc/calloc, or mayb the tasking RAM even corrupted. >.<









Reply by sanylcs June 19, 20092009-06-19
--- In l..., "Paul Curtis" wrote:
>
> Hi,
>
> > The source code of the CTL is not available to me. Can't know how it
> > switches task. But I believe it did that on every cycle of the task's
> > infinite loop, then check the highest priority to run, if no highest
> > priority then run the next same priority task.
>
> Try helping yourself. The source of CTL is shipped with CrossWorks.
>
> $(StudioDir)/ctl/source
>
> But then I guess if you can't find that and don't know much about an RTOS or
> memory management, the source will be beyond your capability.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!
>

OH, thank you. I found the source. my bad never notice that b4 this. was using the library .a file all the time.

but well, as u expected, still wondering what happening to cause the task A run less frequent than task B after using malloc/calloc, or mayb the tasking RAM even corrupted. >.<

Reply by Paul Curtis June 19, 20092009-06-19
Hi,

> The source code of the CTL is not available to me. Can't know how it
> switches task. But I believe it did that on every cycle of the task's
> infinite loop, then check the highest priority to run, if no highest
> priority then run the next same priority task.

Try helping yourself. The source of CTL is shipped with CrossWorks.

$(StudioDir)/ctl/source

But then I guess if you can't find that and dont know much about an RTOS or
memory management, the source will be beyond your capability.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!

Reply by sanylcs June 19, 20092009-06-19
--- In l..., Ralph Hempel wrote:
>
> sanylcs wrote:
>
> > i just did simple test. Two tasks running (task A and task B). no time
> > slice. inside one of the task there is a function (func_A inside task
> > A)(No other things except infinite loop) that use malloc and free the
> > memory before return. task A and B same priority.
>
> Hmmm, looks like TaskA is busier than TaskB doing domething, so TaskB
> runs more frequently.
>
> There's something missing in your description though, how is TaskA
> letting TaskB run if there's no time slicing?
>
> Ralph
>

The source code of the CTL is not available to me. Can't know how it switches task. But I believe it did that on every cycle of the task's infinite loop, then check the highest priority to run, if no highest priority then run the next same priority task.

Reply by sanylcs June 19, 20092009-06-19
Thank you everyone. i guess i am missing something on the memory management. dynamic memory quite new for me, i have no idea what is that ctl_libc_mutex use for, all the while i just know malloc, free, calloc and heap. Never thought there is more things need to be setup when implementing it into OS. That's y i try the simple steps before go into deeper. at least i know it is possible to use them with CTL with ctl_libc_mutex mayb.

Reply by Paul Curtis June 18, 20092009-06-18
Hi,

> > Anyone use CTL of Rowley Crossworks together with malloc/calloc
> (stdlib.h) before?
> >
> > i just did simple test. Two tasks running (task A and task B). no time
> slice. inside one of the task there is a function (func_A inside task
A)(No
> other things except infinite loop) that use malloc and free the memory
> before return. task A and B same priority.
> >
> > I made the task run so that it is (without func_A result)
> > task A
> > task B
> > task A
> > task B
> > ....
> >
> > (with func_A result)
> > task A
> > task B
> > task B
> > task B
> > task A
> > task B
> > task B
> > task B
> > task A
> > ...
> >
> > anyone know why? So we can't use malloc/calloc together with CTL?
>
> ?? I use malloc to allocate stacks for my threads and, once running, they
> create C++ objects and so make malloc calls internally. Works fine.
>
> It is beyond belief that Rowley does not have a sema/mutex protecting the
> memory management calls, though you maybee need to check that the
> multiThreaded versions of the libraries are linked in.

Yes, shock, horror, beyond belief that anybody would consider reading
documentation first:

http://www.rowley.co.uk/documentation/arm_1_7/ctl_libc_mutex.htm

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!

Reply by mjames_doveridge June 18, 20092009-06-18
--- In l..., "sanylcs" wrote:
>
> Anyone use CTL of Rowley Crossworks together with malloc/calloc (stdlib.h) before?
>
> i just did simple test. Two tasks running (task A and task B). no time slice. inside one of the task there is a function (func_A inside task A)(No other things except infinite loop) that use malloc and free the memory before return. task A and B same priority.
>
> I made the task run so that it is (without func_A result)
> task A
> task B
> task A
> task B
> ....
>
> (with func_A result)
> task A
> task B
> task B
> task B
> task A
> task B
> task B
> task B
> task A
> ...
>
> anyone know why? So we can't use malloc/calloc together with CTL?

?? I use malloc to allocate stacks for my threads and, once running, they create C++ objects and so make malloc calls internally. Works fine.

It is beyond belief that Rowley does not have a sema/mutex protecting the memory management calls, though you maybee need to check that the multiThreaded versions of the libraries are linked in.

Rgds,
Martin

Reply by Ralph Hempel June 18, 20092009-06-18
sanylcs wrote:

> i just did simple test. Two tasks running (task A and task B). no time
> slice. inside one of the task there is a function (func_A inside task
> A)(No other things except infinite loop) that use malloc and free the
> memory before return. task A and B same priority.

Hmmm, looks like TaskA is busier than TaskB doing domething, so TaskB
runs more frequently.

There's something missing in your description though, how is TaskA
letting TaskB run if there's no time slicing?

Ralph