Thread safety, C library startup – Comtrol eCos User Manual

Page 360

Advertising
background image

Chapter 13. C and math library overview

environ = (char **)&env;

str = getenv("PATH");

if (str==NULL) {

printf("The current PATH is unset\n");

} else {

printf("The current PATH is \"%s\"\n", str);

}

return 0;

}

Thread safety

The ISO C library has configuration options that control thread safety, i.e. working behavior if multiple threads call
the same function at the same time.

The following functionality has to be configured correctly, or used carefully in a multi-threaded environment:

mblen()

mbtowc()

wctomb()

printf()

(and all standard I/O functions except for

sprintf()

and

sscanf()

strtok()

rand()

and

srand()

signal()

and

raise()

asctime()

,

ctime()

,

gmtime()

, and

localtime()

the

errno

variable

the

environ

variable

date and time settings

In some cases, to make eCos development easier, functions are provided (as specified by POSIX 1003.1) that
define re-entrant alternatives, i.e.

rand_r()

,

strtok_r()

,

asctime_r()

,

ctime_r()

,

gmtime_r()

, and

local-

time_r()

. In other cases, configuration options are provided that control either locking of functions or their shared

data, such as with standard I/O streams, or by using per-thread data, such as with the

errno

variable.

In some other cases, like the setting of date and time, no re-entrant or thread-safe alternative or configuration is
provided as it is simply not a worthwhile addition (date and time should rarely need to be set.)

C library startup

The C library includes a function declared as:

void

cyg_iso_c_start

( void )

256

Advertising