EmbeddedRelated.com
Forums

CTL tasking library with malloc/calloc

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

An Engineer's Guide to the LPC2100 Series

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