httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shane Caraveo" <>
Subject Re: more multithread unsafe stuff
Date Fri, 19 Dec 1997 12:05:25 GMT
> The following functions are thread unsafe, and we use them (some of them
> in core code, like in main/util.c): 
> ctime
> asctime
> localtime
> gmtime
> strtok

Well, one thing m$ did do was make thread safe libraries to compile 
against.  Why?  Because if they didn't, none of their own software 
would work...oh god, what am I saying?!?!?!

Anyway, recently read up on strtok myself, because I had questioned 
the thread safeness of it.  It IS safe between threads, but not 
"within" a thread.  ie. if you call strtok on string a, then strtok 
on string b, then strtok on string a again, you'll get messed up 
results, which I think is normal anyway.  But if two threads are 
calling strtok at the same time, no problem. The static variable used 
for strtok is allocated per thread.

Here's more on the other functions.  There is NO reference as to 
wether the static variable for the time functions is allocated per 
thread, so these may be a problem, but based on the fact that I have 
had no problems running php (cgi) under apache on nt doing dbm and 
odbc accesses, and using calls to some of these functions in php, I 
think they are probably also allocated per thread.  I've run into no 
weird thread problems so far.  (Im on b3 still)

The gmtime, mktime, and localtime functions use the same single,
statically allocated structure to hold their results. Each call to one
of these functions destroys the result of any previous call. 

A call to ctime modifies the single statically allocated buffer used
by the gmtime and localtime functions. Each call to one of these
routines destroys the result of the previous call. ctime shares a
static buffer with the asctime function. Thus, a call to ctime
destroys the results of any previous call to asctime, localtime, or

View raw message