summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorkupries <kupries>2000-04-09 16:04:16 (GMT)
committerkupries <kupries>2000-04-09 16:04:16 (GMT)
commitefe824c8141a780f310fc5aef29a013f53fe541c (patch)
tree939d56df2b9aea3e08214838f501affff23a3ff4 /unix
parent5551a23a1a0fbd1e5febaa29157e06e883049475 (diff)
downloadtcl-efe824c8141a780f310fc5aef29a013f53fe541c.zip
tcl-efe824c8141a780f310fc5aef29a013f53fe541c.tar.gz
tcl-efe824c8141a780f310fc5aef29a013f53fe541c.tar.bz2
2000-04-08 Andreas Kupries <a.kupries@westend.com>
* Overall change: Definition of a public API for the creation of new threads. * generic/tclInt.h (line 1802f): Removed the definition of 'TclpThreadCreate'. (line 793f) Removed the definition of 'Tcl_ThreadCreateProc'. * generic/tcl.h (line 388f): Readded the definition of 'Tcl_ThreadCreateProc'. Added Win32 stuff send in by David Graveraux <davygrvy@bigfoot.com> to that too (__stdcall, ...). Added macros for the default stacksize and allowed flags. * generic/tcl.decls (line 1356f): Added definition of 'Tcl_CreateThread', slot 393 of the stub table. Two new arguments in the public API, for stacksize and flags. * win/tclWinThrd.c: * mac/tclMacThrd.c: Renamed TclpThreadCreate to Tcl_CreateThread, added handling of the stacksize. Flags are currently ignored. * unix/tclUnixThrd.c: See above, but handles joinable flag. Ignores the specified stacksize if the macro HAVE_PTHREAD_ATTR_SETSTACKSIZE is not defined. * generic/tclThreadTest.c (line 363): See below. * unix/tclUnixNotfy.c (line 210): Adapted to the changes above. Uses default stacksize and no flags now. * unic/tcl.m4 (line 382f): Added a check for 'pthread_attr_setstacksize' to detect platforms not implementing this feature of pthreads. If it is implemented, configure will define the macro HAVE_PTHREAD_ATTR_SETSTACKSIZE (See unix/tclUnixThrd.c too). * doc/Thread.3: Added Tcl_CreateThread and its arguments to the list of described functions. Removed stuff about not providing a public C-API for thread-creation.
Diffstat (limited to 'unix')
-rw-r--r--unix/tcl.m45
-rw-r--r--unix/tclUnixNotfy.c6
-rw-r--r--unix/tclUnixThrd.c50
3 files changed, 39 insertions, 22 deletions
diff --git a/unix/tcl.m4 b/unix/tcl.m4
index 0939379..f5a5488 100644
--- a/unix/tcl.m4
+++ b/unix/tcl.m4
@@ -379,6 +379,11 @@ AC_DEFUN(SC_ENABLE_THREADS, [
fi
fi
fi
+
+ # Does the pthread-implementation provide
+ # 'pthread_attr_setstacksize' ?
+
+ AC_CHECK_FUNCS(pthread_attr_setstacksize)
else
TCL_THREADS=0
AC_MSG_RESULT(no (default))
diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c
index 5098f93..7d63228 100644
--- a/unix/tclUnixNotfy.c
+++ b/unix/tclUnixNotfy.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixNotfy.c,v 1.8 2000/04/04 20:28:43 kupries Exp $
+ * RCS: @(#) $Id: tclUnixNotfy.c,v 1.9 2000/04/09 16:04:20 kupries Exp $
*/
#include "tclInt.h"
@@ -207,8 +207,8 @@ Tcl_InitNotifier()
Tcl_MutexLock(&notifierMutex);
if (notifierCount == 0) {
- if (TclpThreadCreate(&notifierThread, NotifierThreadProc, NULL)
- != TCL_OK) {
+ if (Tcl_CreateThread(&notifierThread, NotifierThreadProc, NULL,
+ TCL_THREAD_STACK_DEFAULT, TCL_THREAD_NOFLAGS) != TCL_OK) {
panic("Tcl_InitNotifier: unable to start notifier thread");
}
}
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c
index 53489bc..ca3e592 100644
--- a/unix/tclUnixThrd.c
+++ b/unix/tclUnixThrd.c
@@ -59,7 +59,7 @@ static pthread_mutex_t *allocLockPtr = &allocLock;
/*
*----------------------------------------------------------------------
*
- * TclpThreadCreate --
+ * Tcl_CreateThread --
*
* This procedure creates a new thread.
*
@@ -74,37 +74,49 @@ static pthread_mutex_t *allocLockPtr = &allocLock;
*/
int
-TclpThreadCreate(idPtr, proc, clientData)
+Tcl_CreateThread(idPtr, proc, clientData, stackSize, flags)
Tcl_ThreadId *idPtr; /* Return, the ID of the thread */
Tcl_ThreadCreateProc proc; /* Main() function of the thread */
ClientData clientData; /* The one argument to Main() */
+ int stackSize; /* Size of stack for the new thread */
+ int flags; /* Flags controlling behaviour of
+ * the new thread */
{
pthread_attr_t attr;
int result;
-#ifdef TCL_THREAD_STACK_MIN
- size_t size;
-#endif
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
+#ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
+ if (stackSize != TCL_THREAD_STACK_DEFAULT) {
+ pthread_attr_setstacksize(&attr, (size_t) stackSize);
#ifdef TCL_THREAD_STACK_MIN
- /*
- * Certain systems define a thread stack size that by default is
- * too small for many operations. The user has the option of
- * defining TCL_THREAD_STACK_MIN to a value large enough to work
- * for their needs. This would look like (for 128K min stack):
- * make MEM_DEBUG_FLAGS=-DTCL_THREAD_STACK_MIN=131072L
- *
- * This solution is not optimal, as we should allow the user to
- * specify a size at runtime, but we don't want to slow this function
- * down, and that would still leave the main thread at the default.
- */
- result = pthread_attr_getstacksize(&attr, &size);
- if (!result && (size < TCL_THREAD_STACK_MIN)) {
- pthread_attr_setstacksize(&attr, (size_t) TCL_THREAD_STACK_MIN);
+ } else {
+ /*
+ * Certain systems define a thread stack size that by default is
+ * too small for many operations. The user has the option of
+ * defining TCL_THREAD_STACK_MIN to a value large enough to work
+ * for their needs. This would look like (for 128K min stack):
+ * make MEM_DEBUG_FLAGS=-DTCL_THREAD_STACK_MIN=131072L
+ *
+ * This solution is not optimal, as we should allow the user to
+ * specify a size at runtime, but we don't want to slow this function
+ * down, and that would still leave the main thread at the default.
+ */
+
+ size_t size;
+ result = pthread_attr_getstacksize(&attr, &size);
+ if (!result && (size < TCL_THREAD_STACK_MIN)) {
+ pthread_attr_setstacksize(&attr, (size_t) TCL_THREAD_STACK_MIN);
+ }
+#endif
}
#endif
+ if (! (flags & TCL_THREAD_JOINABLE)) {
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+ }
+
if (pthread_create((pthread_t *)idPtr, &attr,
(void * (*)())proc, (void *)clientData) &&