Index: trunk/src/emx/src/lib/process/beginthr.c
===================================================================
--- trunk/src/emx/src/lib/process/beginthr.c	(revision 1580)
+++ trunk/src/emx/src/lib/process/beginthr.c	(revision 1581)
@@ -23,17 +23,20 @@
 static void _System threadWrapper(__LIBC_PTHREAD pThrd)
 {
-    LIBCLOG_ENTER("pThrd=%p\n", pThrd);
+    LIBCLOG_ENTER("pThrd=%p\n", (void *)pThrd);
     int                         tid;
     EXCEPTIONREGISTRATIONRECORD reg;
     FS_VAR();
 
+    __libc_threadUse(pThrd);
     __libc_Back_threadStartup(&reg);
-    LIBCLOG_MSG("calling thread function %p with arg %p\n", pThrd->u.startup.pfnStart, pThrd->u.startup.pvArg);
+
+    LIBCLOG_MSG("calling thread function %p with arg %p\n", (void *)pThrd->u.startup.pfnStart, pThrd->u.startup.pvArg);
     pThrd->u.startup.pfnStart(pThrd->u.startup.pvArg);
     LIBCLOG_MSG("thread function returned\n");
 
+    FS_SAVE_LOAD();
     __libc_threadTermination(0);
-    tid = _gettid();
-    __libc_threadFree(pThrd);
+    tid = pThrd->tid;
+    __libc_threadDereference(pThrd);
     __libc_Back_threadEnd(&reg);
     FS_SAVE_LOAD();
@@ -46,5 +49,5 @@
 int _beginthread(void (*pfnStart)(void *), void *pvStack, unsigned cbStack, void *pvArg)
 {
-    LIBCLOG_ENTER("pfnStart=%p pvStart=%p cbStack=%d pvArg=%p\n", pfnStart, pvStack, cbStack, pvArg);
+    LIBCLOG_ENTER("pfnStart=%p pvStart=%p cbStack=%d pvArg=%p\n", (void *)pfnStart, pvStack, cbStack, pvArg);
     int             rc;
     TID             tid;
@@ -87,5 +90,5 @@
     else
         errno = EINVAL;
-    __libc_threadFree(pThrd);
+    __libc_threadDereference(pThrd);
     LIBCLOG_RETURN_INT(-1);
 }
@@ -96,10 +99,9 @@
     LIBCLOG_ENTER("\n");
     __LIBC_PTHREAD  pThrd = __libc_threadCurrent();
-    int             tid;
+    int             tid = pThrd->tid;
     FS_VAR();
 
     __libc_threadTermination(0);
-    tid = _gettid();
-    __libc_threadFree(pThrd);
+    __libc_threadDereference(pThrd);
     FS_SAVE_LOAD();
     LIBCLOG_MSG("calling DosExit(%s, 0)\n", tid == 1 ? "EXIT_PROCESS" : "EXIT_THREAD");
Index: trunk/src/emx/src/lib/process/thread_internals.c
===================================================================
--- trunk/src/emx/src/lib/process/thread_internals.c	(revision 1580)
+++ trunk/src/emx/src/lib/process/thread_internals.c	(revision 1581)
@@ -94,5 +94,7 @@
          * Gain exclusive access to the signal stuff.
          */
+#ifdef __NEW_SIGNALS__
         int rc = __libc_back_signalSemRequest();
+#endif
 
         /*
@@ -109,6 +111,8 @@
          * Release semaphore.
          */
+#ifdef __NEW_SIGNALS__
         if (!rc)
             __libc_back_signalSemRelease();
+#endif
     }
     else
@@ -128,6 +132,7 @@
     /*
      * Check that pThrd isn't already in use and set gpTLS to point at pThrd.
-     */
-    assert(!pThrd->pNext && !pThrd->tid && !*__libc_gpTLS);
+     * (*gpTLS might already be pointing to a temporary structure.)
+     */
+    assert(!pThrd->pNext && !pThrd->tid);
     *__libc_gpTLS = pThrd;
 
Index: trunk/src/emx/src/lib/sys/b_threadInit.c
===================================================================
--- trunk/src/emx/src/lib/sys/b_threadInit.c	(revision 1580)
+++ trunk/src/emx/src/lib/sys/b_threadInit.c	(revision 1581)
@@ -37,5 +37,5 @@
 
 
-void __libc_Back_threadInit(__LIBC_PTHREAD pThrd)
+void __libc_Back_threadInit(__LIBC_PTHREAD pThrd, const __LIBC_PTHREAD pParentThrd)
 {
     unsigned        i;
Index: trunk/src/emx/src/lib/sys/b_threadStartup.c
===================================================================
--- trunk/src/emx/src/lib/sys/b_threadStartup.c	(revision 1580)
+++ trunk/src/emx/src/lib/sys/b_threadStartup.c	(revision 1581)
@@ -37,5 +37,5 @@
 #include <InnoTekLIBC/backend.h>
 
-void __libc_Back_threadStartup(void *pExpRegRec, const __LIBC_PTHREAD pParentThrd)
+void __libc_Back_threadStartup(void *pExpRegRec)
 {
     FS_VAR();
Index: trunk/src/emx/src/lib/sys/sharedpm.c
===================================================================
--- trunk/src/emx/src/lib/sys/sharedpm.c	(revision 1580)
+++ trunk/src/emx/src/lib/sys/sharedpm.c	(revision 1581)
@@ -900,4 +900,5 @@
      * This is mostly because we wanna crash before we take the sem.
      */
+#ifdef SIGRTMAX                         /* just make it build. */
     if (pSignal->si_signo <= 0 || pSignal->si_signo > SIGRTMAX)
     {
@@ -905,4 +906,5 @@
         LIBCLOG_RETURN_INT(-EINVAL);
     }
+#endif
     if (pSignal->auReserved[(sizeof(pSignal->auReserved) / sizeof(pSignal->auReserved[0])) - 1])
     {
