Diff
Not logged in

Differences From Artifact [51a5e31e74]:

To Artifact [f0274e7e9d]:


55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80



81
82
83
84
85
86
87
88
89
90



91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

















107






108
109
110
111
112
113
114
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86



87
88
89
90
91
92
93
94
95















96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126







-
+














-
+



+
+
+



-
-
-




+
+
+

+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+









#ifdef TCL_THREADS

/*
 *----------------------------------------------------------------------
 *
 * TclpThreadCreate --
 * Tcl_CreateThread --
 *
 *	This procedure creates a new thread.
 *
 * Results:
 *	TCL_OK if the thread could be created.  The thread ID is
 *	returned in a parameter.
 *
 * Side effects:
 *	A new thread is created.
 *
 *----------------------------------------------------------------------
 */

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
    } 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.
     */
    result = pthread_attr_getstacksize(&attr, &size);
    if (!result && (size < TCL_THREAD_STACK_MIN)) {
	pthread_attr_setstacksize(&attr, (size_t) 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.
	 */

        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) &&
	    pthread_create((pthread_t *)idPtr, NULL,
		    (void * (*)())proc, (void *)clientData)) {
	result = TCL_ERROR;
    } else {