In article <46************ ***********@fre e.teranews.com> ,
Stephen Sprunk <st*****@sprunk .orgwrote:
>what does it means "the function is not thread-safe"?
>It means that the function is likely to behave incorrectly if you call it
from multiple <OT>threads</OT>. The canonical example is strtok().
Well, strtok() is an example of a particularly bad variant, in that
it's not even safe to interleave calls to it in different threads.
But then, it's not even safe to interleave calls to it in *one*
thread: you must finish dealing with one string before starting to
tokenise another. strtok() is not merely not re-entrant: it saves
hidden state between calls.
Functions are considered not thread safe even when things only go
wrong if you call them simultaneously. For example, malloc() might go
wrong if two calls to it simultaneously tried to update internal data
structures. In practice, implementations that provide multi-threading
also provide thread-safe implementations of most of the standard
library functions.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.