delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:mime-version:from:date:message-id:subject:to | |
:content-type; q=dns; s=default; b=Cbdb6FOmCTRHxQ0htSPU77oL8gnvs | |
9YGyaelhHeZJN2v9eHv0oeGNUip489M+Z9QJN5k+3vO9qM5lm+IKwjSGeHTMjbJc | |
bTaTQg3yPl2wdXSs/uXZBVG8ttQ2VNZdyVJc9NWJ2dPLmiHvDZK8dn9Bc3zLmST9 | |
LOn6TsdubWl5JE= | |
DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:mime-version:from:date:message-id:subject:to | |
:content-type; s=default; bh=+eA/im3VEiCWGA67AUBTkBGeIDo=; b=Cmc | |
Q55Wm/EFsadlk1dwq9hLWtxmikrYvOcgfXl9M8jlBnmee1FKD/tAyQsvbiZ0G6Av | |
6YL9r82J56Y48zAja5GgxjU8IC2xxRTIWlTTNeM4WHC1Iz+0r1iMjEO5IbfEbDCD | |
qx2f29b8JxuAt2D0TbrYq8dc/zbHUjr1ZNZyqsS4= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Authentication-Results: | sourceware.org; auth=none |
X-Spam-SWARE-Status: | No, score=-9.9 required=5.0 tests=BAYES_00,ENV_AND_HDR_SPF_MATCH,SPF_PASS,USER_IN_DEF_SPF_WL autolearn=ham version=3.3.2 spammy=III, Cygwin, onetime, one-time |
X-HELO: | mail.apache.org |
MIME-Version: | 1.0 |
From: | "James E. King III" <jking AT apache DOT org> |
Date: | Fri, 23 Nov 2018 11:27:37 -0500 |
Message-ID: | <CAOWZHxdJi1E9APtSXm35LkDU33VqGZSwnGtvOfdHA9PTTJgRjQ@mail.gmail.com> |
Subject: | No thread safety in clock_gettime (hires_ns::prime) |
To: | cygwin AT cygwin DOT com |
X-IsSubscribed: | yes |
--000000000000c5c3bd057b577664 Content-Type: text/plain; charset="UTF-8" Using 32-bit cygwin that I set up yesterday. 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. I prepared a small test that exposes this issue. Given it is a race condition, you have to run the test in a loop for it to happen. I have attached the Makefile and source code. If you run "make test" it will expose the issue: $ make test cc -c -o cyg_hires_clock_race.o cyg_hires_clock_race.c cc cyg_hires_clock_race.o -o cyg_hires_clock_race ERROR: one of the timespec structures was zero: main thread: tv_sec = 356242 tv_nsec = 376075900 2nd thread: tv_sec = 0 tv_nsec = 0 ERROR: one of the timespec structures was zero: main thread: tv_sec = 356242 tv_nsec = 519016800 2nd thread: tv_sec = 0 tv_nsec = 0 ERROR: one of the timespec structures was zero: main thread: tv_sec = 356242 tv_nsec = 734794100 2nd thread: tv_sec = 0 tv_nsec = 0 ERROR: one of the timespec structures was zero: main thread: tv_sec = 356243 tv_nsec = 463632400 2nd thread: tv_sec = 0 tv_nsec = 0 make: *** [Makefile:6: test] Error 1 Relevant cygwin version information: Cygwin DLL version info: DLL version: 2.11.2 DLL epoch: 19 DLL old termios: 5 DLL malloc env: 28 Cygwin conv: 181 API major: 0 API minor: 329 Shared data: 5 DLL identifier: cygwin1 Mount registry: 3 Cygwin registry name: Cygwin Installations name: Installations Cygdrive default prefix: Build date: Shared id: cygwin1S5 --000000000000c5c3bd057b577664 Content-Type: text/plain; charset="US-ASCII"; name="cyg_hires_clock_race.c" Content-Disposition: attachment; filename="cyg_hires_clock_race.c" Content-Transfer-Encoding: base64 Content-ID: <f_jou8ebzq0> X-Attachment-Id: f_jou8ebzq0 LyoKICogQ29weXJpZ2h0IChDKSAyMDE4IEphbWVzIEUuIEtpbmcgSUlJCiAq CiAqIEV4cG9zZXMgYSByYWNlIGNvbmRpdGlvbiBpbiBoaXJlcyBjbG9jayBp bml0aWFsaXphdGlvbgogKiBJZiB0d28gdGhyZWFkcyBjYWxsIDo6Y2xvY2tf Z2V0dGltZShDTE9DS19NT05PVE9OSUMpIHRoZXkKICogd2lsbCByYWNlIHRv IHBlcmZvcm0gb25lLXRpbWUgZ2xvYmFsIGluaXRpYWxpemF0aW9uLgogKiBE dXJpbmcgdGhpcyByYWNlIGl0IGlzIHBvc3NpYmxlIHRvIHNlZSB0aGUgdGlt ZXNwZWMgZmlsbGVkCiAqIGluIGJ5IDo6Y2xvY2tfZ2V0dGltZSBjYW4gaGF2 ZSB0dl9zZWMgPT0gMCAmJiB0dl9uc2VjID09IDAKICogCiAqIEFzIHRoaXMg aXMgYSByYWNlIHlvdSBoYXZlIHRvIHJ1biB0aGUgdGVzdCBpbiBhIGxvb3Ag dG8gY2F0Y2ggaXQuCiAqLwoKI2luY2x1ZGUgPGFzc2VydC5oPgojaW5jbHVk ZSA8cHRocmVhZC5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHRp bWUuaD4KCnZvaWQgKmZpbGxfdHModm9pZCAqdnRzKQp7CiAgICBzdHJ1Y3Qg dGltZXNwZWMgKnB0cyA9IChzdHJ1Y3QgdGltZXNwZWMgKil2dHM7CiAgICBh c3NlcnQoIWNsb2NrX2dldHRpbWUoQ0xPQ0tfTU9OT1RPTklDLCBwdHMpKTsK ICAgIHJldHVybiBOVUxMOwp9CgppbnQgbWFpbigpCnsKICAgIHN0cnVjdCB0 aW1lc3BlYyBtYWluX3RzOwogICAgc3RydWN0IHRpbWVzcGVjIHRocmVhZF90 czsKCiAgICBwdGhyZWFkX3QgdGhyOwogICAgYXNzZXJ0KCFwdGhyZWFkX2Ny ZWF0ZSgmdGhyLCBOVUxMLCAmZmlsbF90cywgJnRocmVhZF90cykpOwogICAg KHZvaWQpZmlsbF90cygmbWFpbl90cyk7CiAgICBhc3NlcnQoIXB0aHJlYWRf am9pbih0aHIsIE5VTEwpKTsKCiAgICBpbnQgZmFpbGVkID0KICAgICAgICAo KCAgbWFpbl90cy50dl9zZWMgPT0gMCAmJiAgIG1haW5fdHMudHZfbnNlYyA9 PSAwKSB8fAogICAgICAgICAodGhyZWFkX3RzLnR2X3NlYyA9PSAwICYmIHRo cmVhZF90cy50dl9uc2VjID09IDApKTsKCiAgICBpZiAoZmFpbGVkKQogICAg ewogICAgICAgIGZwcmludGYoc3RkZXJyLCAiRVJST1I6IG9uZSBvZiB0aGUg dGltZXNwZWMgc3RydWN0dXJlcyB3YXMgemVybzpcbiIpOwoJZnByaW50Zihz dGRlcnIsICJtYWluIHRocmVhZDogdHZfc2VjID0gJTEwdSB0dl9uc2VjID0g JTEwdVxuIiwgICBtYWluX3RzLnR2X3NlYywgICBtYWluX3RzLnR2X25zZWMp OwoJZnByaW50ZihzdGRlcnIsICIgMm5kIHRocmVhZDogdHZfc2VjID0gJTEw dSB0dl9uc2VjID0gJTEwdVxuIiwgdGhyZWFkX3RzLnR2X3NlYywgdGhyZWFk X3RzLnR2X25zZWMpOwoJcmV0dXJuIDE7CiAgICB9CgogICAgcmV0dXJuIDA7 Cn0K --000000000000c5c3bd057b577664 Content-Type: application/octet-stream; name=Makefile Content-Disposition: attachment; filename=Makefile Content-Transfer-Encoding: base64 Content-ID: <f_jou8ec031> X-Attachment-Id: f_jou8ec031 YWxsOiBjeWdfaGlyZXNfY2xvY2tfcmFjZQoKY3lnX2hpcmVzX2Nsb2NrX3Jh Y2U6IGN5Z19oaXJlc19jbG9ja19yYWNlLm8KCnRlc3Q6IGN5Z19oaXJlc19j bG9ja19yYWNlCglAIGZvciBsb29wIGluIHsxLi4xMDB9OyBkbyAuL2N5Z19o aXJlc19jbG9ja19yYWNlLmV4ZTsgZG9uZQo= --000000000000c5c3bd057b577664 Content-Type: text/plain; charset=us-ascii -- 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 --000000000000c5c3bd057b577664--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |