Subj : thread safe of time() To : comp.programming.threads From : Da Wang Date : Tue Feb 22 2005 09:50 pm 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); time(&rawtime); timeinfo=localtime_r(&rawtime,timeinfo); if (timeinfo==NULL){ perror("localtime_r()--Cannot get system time. ServerExit"); exit(2); } localtm=asctime_r(timeinfo,localtm,26); if (localtm==NULL){ perror("asctime_r()--Cannot get system time. Server Exit"); exit(2); } free(timeinfo); return localtm; } .