Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2006-08-21
08:39 • Closed ticket [1457797fff]: io.test hangs in darwin threaded 64bit build plu... artifact: 1b6352f975 user: das
2006-03-24
23:08 • Ticket [1457797fff]: 4 changes artifact: 5ad7a8054b user: das
15:32 • New ticket [1457797fff]. artifact: c2a5bfd5ba user: das

io.test hangs in darwin threaded 64bit build

Closed / Fixed1457797fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 20 years ago
Descriptionplain2006-03-24 15:32:57
On a dual proc G5 running Mac OS X Tiger, tcl configured with
--enable-threads --enable-64bit
hangs intermittently in various tests in io.test, but AFAICT only in those 
that involve [after]. The rest of the testsuite runs fine.

examples of hanging tests are io-6.56, io-13.6, io-14.9 and io-53.7 (the 
most common).

the problem goes away when configuring without --enable-threads

32bit builds on the same box are also ok, independently of the presence 
of --enable-threads and/or --disable-corefoundation (which is 
automatically on for 64bit).
dasplain2006-03-24 23:08:54
Logged In: YES 
user_id=90580

the same issue appears to exists on HEAD, where I've seen tests io-39.17 and 
io-53.7 hang intermittently, again with the latter being the most common.
non-threaded and 32bit HEAD builds are again fine...
dasplain2006-08-21 08:39:09
Logged In: YES 
user_id=90580

It seems that this is due to an OS bug in pthread_cond_timedwait(): when 
giving it an expiry time that has already passed (or maybe is only a very short 
time in the future), it waits forever instead of returning immediately like in 
32-bit mode (and like on other platforms).
This causes intermittent hangs in [vwait] when using the unix notifier which is 
default with 64-bit (it does not affect the CF notifier and I cannot reproduce it 
on the same machine in a 32-bit build with the unix notifier i.e. configured -
without-corefoundation).
I have now worked around the issue by not passing very small timeouts to 
Tcl_ConditionWait() and doing a poll instead in those cases. The current 10 
usec threshold in the code for the expiry time has been empirically 
determined on a dual G5, it seems to avoid all hangs in the testsuite on that 
machine, but it would be useful if others with 64-bit capable machines could 
check that this works for them as well (just try running io.test many times, 
varying the load on the machine seems to make a difference as well). In 
particular, I don't know if this problem even exists on x86_64, but to be safe 
I've turned on the workaround for apple LP64 in general:

Index: unix/tclUnixNotfy.c
===============================================
====================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixNotfy.c,v
retrieving revision 1.31
diff -u -p -r1.31 tclUnixNotfy.c
--- unix/tclUnixNotfy.c10 Aug 2006 12:15:32 -00001.31
+++ unix/tclUnixNotfy.c20 Aug 2006 22:13:15 -0000
@@ -740,7 +740,17 @@ Tcl_WaitForEvent(
     Tcl_MutexLock(&notifierMutex);
 
     waitForFiles = (tsdPtr->numFdBits > 0);
-    if (myTimePtr != NULL && myTimePtr->sec == 0 && myTimePtr->usec 
== 0) {
+    if (myTimePtr != NULL && myTimePtr->sec == 0 && (myTimePtr->usec 
== 0
+#if defined(__APPLE__) && defined(__LP64__)
+    /*
+     * On 64-bit Darwin, pthread_cond_timedwait() appears to have a bug
+     * that causes it to wait forever when passed an absolute time which
+     * has already been exceeded by the system time; as a workaround,
+     * when given a very brief timeout, just do a poll. [Bug 1457797]
+     */
+    || myTimePtr->usec < 10
+#endif
+    )) {
 /*
  * Cannot emulate a polling select with a polling condition variable.
  * Instead, pretend to wait for files and tell the notifier thread
Log in (anonymous is fine) to add a comment.