Mercurial > cpython-lru_cache-weakref
diff Python/thread_nt.h @ 38578:0b2b076e5908 legacy-trunk
Patch #1454481: Make thread stack size runtime tunable.
| author | Andrew MacIntyre <andymac@bullseye.apana.org.au> |
|---|---|
| date | Sun, 04 Jun 2006 12:31:09 +0000 |
| parents | aa620856e8a3 |
| children | 19430cdff2bd |
line wrap: on
line diff
--- a/Python/thread_nt.h Sun Jun 04 06:19:31 2006 +0000 +++ b/Python/thread_nt.h Sun Jun 04 12:31:09 2006 +0000 @@ -185,7 +185,7 @@ if (obj.done == NULL) return -1; - rv = _beginthread(bootstrap, 0, &obj); /* use default stack size */ + rv = _beginthread(bootstrap, _pythread_stacksize, &obj); if (rv == (Py_uintptr_t)-1) { /* I've seen errno == EAGAIN here, which means "there are * too many threads". @@ -313,3 +313,37 @@ if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock))) dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError())); } + +/* minimum/maximum thread stack sizes supported */ +#define THREAD_MIN_STACKSIZE 0x8000 /* 32kB */ +#define THREAD_MAX_STACKSIZE 0x10000000 /* 256MB */ + +/* set the thread stack size. + * Return 1 if an exception is pending, 0 otherwise. + */ +static int +_pythread_nt_set_stacksize(size_t size) +{ + /* set to default */ + if (size == 0) { + _pythread_stacksize = 0; + return 0; + } + + /* valid range? */ + if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) { + _pythread_stacksize = size; + return 0; + } + else { + char warning[128]; + snprintf(warning, + 128, + "thread stack size of %#x bytes not supported on Win32", + size); + return PyErr_Warn(PyExc_RuntimeWarning, warning); + } +} + +#undef THREAD_SET_STACKSIZE +#define THREAD_SET_STACKSIZE(x) _pythread_nt_set_stacksize(x)
