Subj : Re: thread safe of time() To : comp.programming.threads From : Casper H.S. Dik Date : Wed Feb 23 2005 08:53 am Da Wang writes: >Hi, I am using POSIX threads lib and work on sun sparc machine: >in my code i need to get the system date and I wrote the following code. > I am wondering whether the statement "time(&rawtime)" is thread safe >or not. If it is not safe, how to solve that problem? Thanks. >--------- >char* >getLocalTime() >{ > char *localtm; > time_t rawtime; > struct tm *timeinfo; > timeinfo=(struct tm*)malloc(sizeof(struct tm)); > localtm=(char*)malloc(sizeof(char)*27); Do not use casts for malloc return values; the casts may hide errors. You read the manual page and at the bottom you'll find: ATTRIBUTES See attributes(5) for descriptions of the following attri- butes: ____________________________________________________________ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |_____________________________|_____________________________| | MT-Level | Async-Signal-Safe | |_____________________________|_____________________________| Casper -- Expressed in this posting are my opinions. They are in no way related to opinions held by my employer, Sun Microsystems. Statements on Sun products included here are not gospel and may be fiction rather than truth. .