Thread creation, Name, Synopsis – Comtrol eCos User Manual

Page 39: Description, Thread entry point

Advertising
background image

Thread creation

Name

cyg_thread_create

— Create a new thread

Synopsis

#include

<

cyg/kernel/kapi.h

>

void cyg_thread_create(cyg_addrword_t sched_info, cyg_thread_entry_t* entry ,

cyg_addrword_t entry_data, char* name, void* stack_base, cyg_ucount32 stack_size,

cyg_handle_t* handle, cyg_thread* thread);

Description

The

cyg_thread_create

function allows application code and eCos packages to create new threads. In many

applications this only happens during system initialization and all required data is allocated statically. However
additional threads can be created at any time, if necessary. A newly created thread is always in suspended state
and will not start running until it has been resumed via a call to

cyg_thread_resume

. Also, if threads are created

during system initialization then they will not start running until the eCos scheduler has been started.

The

name

argument is used primarily for debugging purposes, making it easier to keep track of which

cyg_thread structure is associated with which application-level thread. The kernel configuration option

CYGVAR_KERNEL_THREADS_NAME

controls whether or not this name is actually used.

On creation each thread is assigned a unique handle, and this will be stored in the location pointed at by the

handle

argument. Subsequent operations on this thread including the required

cyg_thread_resume

should use

this handle to identify the thread.

The kernel requires a small amount of space for each thread, in the form of a cyg_thread data structure, to hold
information such as the current state of that thread. To avoid any need for dynamic memory allocation within the
kernel this space has to be provided by higher-level code, typically in the form of a static variable. The

thread

argument provides this space.

Thread Entry Point

The entry point for a thread takes the form:

void

thread_entry_function(cyg_addrword_t data)

{

...

}

39

Advertising