Web lists-archives.com

Re: No thread safety in clock_gettime (hires_ns::prime)




On Mon, 26 Nov 2018 18:01:40, Corinna Vinschen  wrote:
> 
> On Nov 23 11:27, James E. King III wrote:
[snip]

> > I found that a call to
> > clock_gettime(CLOCK_MONOTONIC, ..) has a one-time initialization that
> > is not thread-safe.  If two threads call this at the same time, they
> > will race.  The results I am seeing are typically that one of the two
> > callers get a timespec structure with zero values, and no error return
> > code from the call.
> 
> Thanks for the testcase, but I can't reproduce the problem, neither on
> 32 bit nor on 64 bit.  I tweaked your makefile to have a 100K loop I
> started multiple times with differently optimzed code, but to no avail.
> 
> To account for that, I inspected the code doing the initialization and
> found that it uses REALTIME priority when trying to make sure multiple
> threads don't collide.  This is a bit on the dangerous side, apparently.
> 
> I tweaked the code to use a spinlock instead.
> 
> I'm just about to upload new developer snapshots to
> https://cygwin.com/snapshots/
> 
> Should be up in 10 mins or so.  Can you please try if this fixes the
> problem for you?

 - only replaced the cygwin1.dll ...

Henri

64-@@ uname -a
CYGWIN_NT-6.1 Seven 2.11.3(0.329/5/3)  x86_64 Cygwin
64-@@ ls -l /bin/cygwin1*
-rwxr-xr-x 1 Henri None 3339661 Nov  8 14:36 /bin/cygwin1-2.11.2.X
-rwxr-xr-x 1 Henri None 3337995 Nov 26 18:43 /bin/cygwin1-64-20181126.X
-rwxr-xr-x 1 Henri None 3337995 Nov 26 18:43 /bin/cygwin1.dll
64-@@ cd threads
64-@@ make test
64-@@ make test
64-@@ make test
64-@@ make test
64-@@ make test
64-@@ make test
64-@@ make test
64-@@ make test
64-@@ vi Makefile
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ #... wait a while ...
64-@@ for loop in {1..100}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..1000}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..1000}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..1000}; do ./cyg_hires_clock_race.exe; done
64-@@ for loop in {1..10000}; do ./cyg_hires_clock_race.exe; done
64-@@# That is enough!

=====


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple