|
From: <cn...@us...> - 2010-05-04 07:06:19
|
Revision: 722
http://hgengine.svn.sourceforge.net/hgengine/?rev=722&view=rev
Author: cnlohr
Date: 2010-05-04 07:06:13 +0000 (Tue, 04 May 2010)
Log Message:
-----------
"fix" threads on Linux i686, or rather, avoid potentially problematic area
Modified Paths:
--------------
Mercury2/src/MercuryThreads.cpp
Mercury2/src/MercuryThreads.h
Modified: Mercury2/src/MercuryThreads.cpp
===================================================================
--- Mercury2/src/MercuryThreads.cpp 2010-05-03 02:28:59 UTC (rev 721)
+++ Mercury2/src/MercuryThreads.cpp 2010-05-04 07:06:13 UTC (rev 722)
@@ -9,6 +9,26 @@
#include <stdint.h>
#endif
+//#define EXTRA_DEBUG_ON_THREAD_FAIL
+
+#ifdef EXTRA_DEBUG_ON_THREAD_FAIL
+#include <MercuryBacktrace.h>
+void ThreadPrintBacktrace()
+{
+ fprintf( stderr, "Printing backtrace...\n" );
+ char buffer[2048];
+ int i = cnget_backtrace( 1, buffer, 2048 );
+ fprintf( stderr, "%s\n", buffer );
+}
+
+#else
+void ThreadPrintBacktrace()
+{
+}
+#endif
+
+
+
//XXX WARNING in windows mutex of the same name are shared!!!
//we can not give mutexes a default name
@@ -169,13 +189,22 @@
switch( r )
{
case WAIT_TIMEOUT:
+ //
+ ThreadPrintBacktrace();
+ //
fprintf(stderr, "Mutex held by thread ID 0x%x timed out (%d locks)\n", m_heldBy, iLockCount );
return false;
case WAIT_FAILED:
+ //
+ ThreadPrintBacktrace();
+ //
fprintf(stderr, "Mutex held by thread ID 0x%x failed (%d locks)\n", m_heldBy, iLockCount );
return false;
}
#else
+ //This seems to have some curious behavior in i386 Linux (tested and found problematic in Ubuntu 9.04)
+ //which can cause a crash of the program in an infinite loop. I do not know what is casuing it, but
+ //My general suggestion is that it be avoided - Charles
if ( lMilliseconds < 0xFFFFFF )
{
timeval t;
@@ -205,6 +234,7 @@
fprintf(stderr, "Max Recursive Locks Reached\n");
return false;
case ETIMEDOUT:
+ ThreadPrintBacktrace();
fprintf(stderr, "Mutex held by thread ID 0x%lx timed out (%d locks)\n", m_heldBy, iLockCount );
return false;
}
Modified: Mercury2/src/MercuryThreads.h
===================================================================
--- Mercury2/src/MercuryThreads.h 2010-05-03 02:28:59 UTC (rev 721)
+++ Mercury2/src/MercuryThreads.h 2010-05-04 07:06:13 UTC (rev 722)
@@ -123,8 +123,8 @@
{
//loop until we get a lock but use a timeout so we are warned
//of a held mutex indicating a possible deadlock
- bool l = m_mutex->Wait(1000);
- while (!l) m_mutex->Wait(1000);
+ bool l = m_mutex->Wait(0xFFFFFF);
+ while (!l) m_mutex->Wait(0xFFFFFF);
}
~AutoMutexLock()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|