User`s guide

18
K
A
DAK
KwikNet Overview
Memory Allocation Protection
When operating in a multitasking environment, the memory allocation services must be
thread-safe. If the services you have chosen to use are not thread-safe, KwikNet can be
configured to use the memory locking mechanism in its OS Interface Module to protect
access to the unsafe memory allocation services.
If you use standard C for memory allocation within a multitasking system, you will have
to use KwikNet's locking service to protect access to the library functions unless your C
runtime library provides thread-safe implementations of its memory management
functions.
If you use the KwikNet simple heap for memory allocation, the memory allocation
services will be automatically locked by the Turbo Treck TCP/IP Stack if required.
However, if you dynamically assign the memory page(s) in a multitasking system using
the C library
malloc() or your own memory acquisition function kn_msmemacquire(),
you will have to use
KwikNet's locking service to protect access to these functions unless
they are inherently thread-safe.
If you use your OS memory allocation services in a multitasking system, you must be
sure that they are thread-safe. If necessary, you can use KwikNet's locking service to
protect access to the OS memory services. Special care must be taken if you dynamically
assign a memory region for use by the OS. In this case, the C library function malloc()
or your memory acquisition function kn_msmemacquire() will be called as soon as your
OS is ready for use, long before KwikNet is operational. Hence you cannot use KwikNet's
locking service to protect access to these functions. It is your responsibility to ensure that
these functions are thread-safe at the time your application starts execution. In most
cases this requirement will be met because the OS interface function kn_osready()
executes before any other application tasks are started.
If KwikNet is used with AMX and standard C is used for memory allocation, you must
enable the memory locking protection in the KwikNet OS interface to protect the unsafe
services in the C library. If your C library is thread-safe, you will not require locking.
If the
KwikNet simple heap is used with AMX, you will not require locking. The initial
memory acquisition process and all subsequent memory allocation operations are
automatically thread-safe.
If KwikNet is used with the AMX Memory Manager, you will not require locking. The
initial memory acquisition process and all subsequent memory allocation operations are
automatically thread-safe.
The KwikNet sample programs provided for use with AMX use the AMX Memory
Manager to allocate memory from a static array. These services are thread-safe.
The examples provided with the KwikNet Porting Kit are ready for use with standard C. If
you port
KwikNet to a multitasking RTOS, be sure to implement the memory protection
mechanism or provide access to thread-safe services within the RTOS.