This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Nov 23 11:27, James E. King III wrote:
> Using 32-bit cygwin that I set up yesterday.

Don't do that.  Use 64 bit Cygwin whenever possible.  32 bit is a lost
cause.

> 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?


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]