jmartrican
January 12th, 2009, 01:09 AM
I was using boost::date_time to get timestamps but in my tests C's gettimeofday() followed with localtime is faster. I have a bunch of threads that will be calling gettimeofday and localtime quite often.
So here are my questions.
1) From reading Open Group's documentation on locatime (http://www.opengroup.org/onlinepubs/007908799/xsh/localtime.html), I deduce that localtime is not reentrant because it seems like localtime is using some shared memory space for storing a copy of an object called 'tm'. Is it shared across a thread or across you program? Is it allocated some where in the time.h code? This might be a stupid question but I just want to be sure of why it is not reentrant.
2) The Open Group mentions that there is localtime_r which is suppose to be reentrant. So my question is how is it made reentrant and do we need to delete the tm* that is passed to it? Has anyone used it before (or know how it works) and can speak for its reentrant properties?
thanks!
So here are my questions.
1) From reading Open Group's documentation on locatime (http://www.opengroup.org/onlinepubs/007908799/xsh/localtime.html), I deduce that localtime is not reentrant because it seems like localtime is using some shared memory space for storing a copy of an object called 'tm'. Is it shared across a thread or across you program? Is it allocated some where in the time.h code? This might be a stupid question but I just want to be sure of why it is not reentrant.
2) The Open Group mentions that there is localtime_r which is suppose to be reentrant. So my question is how is it made reentrant and do we need to delete the tm* that is passed to it? Has anyone used it before (or know how it works) and can speak for its reentrant properties?
thanks!