summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2012-11-13 21:16:13 (GMT)
committerdgp <dgp@users.sourceforge.net>2012-11-13 21:16:13 (GMT)
commitc45b50173ca951f918919aedca75f22bf1ccf7b3 (patch)
treee03b318dbb0e29de111d837975f499df3be1a176
parentba16c7a4403b1fa99daafb9292751bf572c09616 (diff)
parent5b2d20cdcbe08cf350f3adc4e83618cdd5720cf7 (diff)
downloadtcl-c45b50173ca951f918919aedca75f22bf1ccf7b3.zip
tcl-c45b50173ca951f918919aedca75f22bf1ccf7b3.tar.gz
tcl-c45b50173ca951f918919aedca75f22bf1ccf7b3.tar.bz2
360894 Threads inherit floating point config from their creator thread
-rw-r--r--win/tclWinThrd.c74
1 files changed, 70 insertions, 4 deletions
diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c
index 13fd411..21d422f 100644
--- a/win/tclWinThrd.c
+++ b/win/tclWinThrd.c
@@ -13,6 +13,7 @@
#include "tclWinInt.h"
#include <fcntl.h>
+#include <float.h>
#include <io.h>
#include <sys/stat.h>
@@ -122,6 +123,65 @@ typedef struct WinCondition {
struct ThreadSpecificData *lastPtr;
} WinCondition;
+/*
+ * The per thread data passed from TclpThreadCreate
+ * to TclWinThreadStart.
+ */
+
+typedef struct WinThread {
+ LPTHREAD_START_ROUTINE lpStartAddress; /* Original startup routine */
+ LPVOID lpParameter; /* Original startup data */
+ unsigned int fpControl; /* Floating point control word from the
+ * main thread */
+} WinThread;
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclWinThreadStart --
+ *
+ * This procedure is the entry point for all new threads created
+ * by Tcl on Windows.
+ *
+ * Results:
+ * Various, depending on the result of the wrapped thread start
+ * routine.
+ *
+ * Side effects:
+ * Arbitrary, since user code is executed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static DWORD WINAPI
+TclWinThreadStart(
+ LPVOID lpParameter) /* The WinThread structure pointer passed
+ * from TclpThreadCreate */
+{
+ WinThread *winThreadPtr = (WinThread *) lpParameter;
+ unsigned int fpmask;
+ LPTHREAD_START_ROUTINE lpOrigStartAddress;
+ LPVOID lpOrigParameter;
+
+ if (!winThreadPtr) {
+ return TCL_ERROR;
+ }
+
+ fpmask = _MCW_EM | _MCW_RC | _MCW_PC;
+
+#if defined(_MSC_VER) && _MSC_VER >= 1200
+ fpmask |= _MCW_DN;
+#endif
+
+ _controlfp(winThreadPtr->fpControl, fpmask);
+
+ lpOrigStartAddress = winThreadPtr->lpStartAddress;
+ lpOrigParameter = winThreadPtr->lpParameter;
+
+ ckfree((char *)winThreadPtr);
+ return lpOrigStartAddress(lpOrigParameter);
+}
/*
*----------------------------------------------------------------------
@@ -149,17 +209,23 @@ TclpThreadCreate(idPtr, proc, clientData, stackSize, flags)
int flags; /* Flags controlling behaviour of
* the new thread */
{
+ WinThread *winThreadPtr; /* Per-thread startup info */
HANDLE tHandle;
+ winThreadPtr = (WinThread *)ckalloc(sizeof(WinThread));
+ winThreadPtr->lpStartAddress = (LPTHREAD_START_ROUTINE) proc;
+ winThreadPtr->lpParameter = clientData;
+ winThreadPtr->fpControl = _controlfp(0, 0);
+
EnterCriticalSection(&joinLock);
#if defined(_MSC_VER) || defined(__MSVCRT__) || defined(__BORLANDC__)
- tHandle = (HANDLE) _beginthreadex(NULL, (unsigned) stackSize, proc,
- clientData, 0, (unsigned *)idPtr);
+ tHandle = (HANDLE) _beginthreadex(NULL, (unsigned) stackSize,
+ (Tcl_ThreadCreateProc*) TclWinThreadStart, winThreadPtr,
+ 0, (unsigned *)idPtr);
#else
tHandle = CreateThread(NULL, (DWORD) stackSize,
- (LPTHREAD_START_ROUTINE) proc, (LPVOID) clientData,
- (DWORD) 0, (LPDWORD)idPtr);
+ TclWinThreadStart, winThreadPtr, 0, (LPDWORD)idPtr);
#endif
if (tHandle == NULL) {