EmbeddedRelated.com
Forums

CTL tasking library with malloc/calloc

Started by sanylcs June 18, 2009
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?

An Engineer's Guide to the LPC2100 Series

> anyone know why? So we can't use malloc/calloc together with CTL?

Yeah, you can.

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

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

--- 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

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!

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.

--- 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.

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!

--- 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. >.<

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. >.<