No thread safety in clock_gettime (hires_ns::prime)
Corinna Vinschen
corinna-cygwin@cygwin.com
Tue Nov 27 09:37:00 GMT 2018
On Nov 26 19:07, Houder wrote:
> 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!
Thanks a lot for testing! (Particulary since I couldn't even
reproduce this on W7)
Corinna
--
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20181127/de791737/attachment.sig>
More information about the Cygwin
mailing list