Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - clock_gettime multithreaded ?: (6 Items)
   
clock_gettime multithreaded ?  
Hy 

since some weeks I have a problem with getting the Realtimeclock values by "clock_gettime". Sometimes I gets a timevalue
 back which is not a correct one. 
The system on which the software is running is a X86 plattform with a dualcore prozessor with multiple threads. Cause of
 timing issues it would be possible that

these calls ->

coBindCpu_m.vfuBindCpu(0);
lRetVal_l = clock_gettime( CLOCK_REALTIME, &tActTimeSpec_l);
coBindCpu_m.vfuRestoreCpu();

is done in parallel. 

Is it possible that the function clock_gettime is not threadsafe or that it has the same problem like fopen, fclose ... 
in a multithreaded environment?

Best regards
Dieter
Re: clock_gettime multithreaded ?  
There is code in _syspage_time() (called by clock_gettime() ) sepecifically
to check for clock interrupts disturbing the clock read. It loops until it
gets a stable reading.

So I'd say it's thread safe.

-ad

Dieter Bittner wrote:
> Hy
> 
> since some weeks I have a problem with getting the Realtimeclock values 
> by "clock_gettime". Sometimes I gets a timevalue back which is not a 
> correct one.
> 
> The system on which the software is running is a X86 plattform with a 
> dualcore prozessor with multiple threads. Cause of timing issues it 
> would be possible that
> 
> these calls ->
> 
> coBindCpu_m.vfuBindCpu(0);
> lRetVal_l = clock_gettime( CLOCK_REALTIME, &tActTimeSpec_l);
> coBindCpu_m.vfuRestoreCpu();
> 
> is done in parallel.
> 
> Is it possible that the function clock_gettime is not threadsafe or that 
> it has the same problem like fopen, fclose ... in a multithreaded 
> environment?
> 
> Best regards
> Dieter
> 
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post7700
> 
Re: clock_gettime multithreaded ?  
Hi Attila 
thanks for the response. If the function is threadsafe do you have another idea why it sometime delivers not wrong 
results.
Does it perhaps has also problems with filedescriptors (if it uses some) like fopen of fclose ?

Best regards
Dieter
Re: clock_gettime multithreaded ?  
What sort of 'wrong' are you seeing?

Also, what kernel version are you running?

Cheers,

Colin

Dieter Bittner wrote:
> Hi Attila
> thanks for the response. If the function is threadsafe do you have 
> another idea why it sometime delivers not wrong results.
> 
> Does it perhaps has also problems with filedescriptors (if it uses some) 
> like fopen of fclose ?
> 
> Best regards
> Dieter
> 
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post7729
> 

-- 
cburgess@qnx.com
Re: clock_gettime multithreaded ?  
Hi 

the wrong results I get is a wrong value in "tv_sec" in the structure "timespec". 
I assume this. It is not proofed but very likely.

The kernel version I am running is 6.3.2 

Re: clock_gettime multithreaded ?  
I'm using the tv_nsec field returned in clock_gettime() and a call before the output of 500 words over a pci bus and the
 call after show the exact same tv_nsec which is almost impossible.  
Bob Davis