# HG changeset patch # User Adam Chlipala # Date 1312309897 14400 # Node ID 4d0b80dd4c374fdc3d10253d5034b0717d185124 # Parent 001638622c4f2378cc15d524fc5b3fcec5553b32 Introduce URWEB_STACK_SIZE environment variable (based on a patch by Hao Deng) diff -r 001638622c4f -r 4d0b80dd4c37 doc/manual.tex --- a/doc/manual.tex Tue Aug 02 13:48:26 2011 -0400 +++ b/doc/manual.tex Tue Aug 02 14:31:37 2011 -0400 @@ -321,6 +321,15 @@ A word of warning: as for demo generation, tutorial generation calls Emacs to syntax-highlight Ur code. +\subsection{Run-Time Options} + +Compiled applications consult a few environment variables to modify their behavior: + +\begin{itemize} + \item \cd{URWEB\_NUM\_THREADS}: alternative to the \cd{-t} command-line argument (currently used only by FastCGI) + \item \cd{URWEB\_STACK\_SIZE}: size of per-thread stacks, in bytes +\end{itemize} + \section{Ur Syntax} diff -r 001638622c4f -r 4d0b80dd4c37 include/request.h --- a/include/request.h Tue Aug 02 13:48:26 2011 -0400 +++ b/include/request.h Tue Aug 02 14:31:37 2011 -0400 @@ -32,4 +32,6 @@ void *client_pruner(void *data); +int pthread_create_big(pthread_t *outThread, void *foo, void *threadFunc, void *arg); + #endif diff -r 001638622c4f -r 4d0b80dd4c37 src/c/fastcgi.c --- a/src/c/fastcgi.c Tue Aug 02 13:48:26 2011 -0400 +++ b/src/c/fastcgi.c Tue Aug 02 14:31:37 2011 -0400 @@ -569,7 +569,7 @@ { pthread_t thread; - if (pthread_create(&thread, NULL, client_pruner, &ls)) { + if (pthread_create_big(&thread, NULL, client_pruner, &ls)) { fprintf(stderr, "Error creating pruner thread\n"); return 1; } @@ -578,7 +578,7 @@ for (i = 0; i < nthreads; ++i) { pthread_t thread; names[i] = i; - if (pthread_create(&thread, NULL, worker, &names[i])) { + if (pthread_create_big(&thread, NULL, worker, &names[i])) { fprintf(stderr, "Error creating worker thread #%d\n", i); return 1; } diff -r 001638622c4f -r 4d0b80dd4c37 src/c/http.c --- a/src/c/http.c Tue Aug 02 13:48:26 2011 -0400 +++ b/src/c/http.c Tue Aug 02 14:31:37 2011 -0400 @@ -311,7 +311,7 @@ { pthread_t thread; - if (pthread_create(&thread, NULL, client_pruner, &ls)) { + if (pthread_create_big(&thread, NULL, client_pruner, &ls)) { fprintf(stderr, "Error creating pruner thread\n"); return 1; } @@ -320,7 +320,7 @@ for (i = 0; i < nthreads; ++i) { pthread_t thread; names[i] = i; - if (pthread_create(&thread, NULL, worker, &names[i])) { + if (pthread_create_big(&thread, NULL, worker, &names[i])) { fprintf(stderr, "Error creating worker thread #%d\n", i); return 1; } diff -r 001638622c4f -r 4d0b80dd4c37 src/c/request.c --- a/src/c/request.c Tue Aug 02 13:48:26 2011 -0400 +++ b/src/c/request.c Tue Aug 02 14:31:37 2011 -0400 @@ -123,12 +123,40 @@ }; } +static unsigned long long stackSize; + +int pthread_create_big(pthread_t *outThread, void *foo, void *threadFunc, void *arg) +{ + int err; + pthread_attr_t stackSizeAttribute; + + err = pthread_attr_init(&stackSizeAttribute); + if (err) return err; + + if (stackSize > 0) { + err = pthread_attr_setstacksize(&stackSizeAttribute, stackSize); + if (err) return err; + } + + return pthread_create(outThread, &stackSizeAttribute, threadFunc, arg); +} + void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) { uw_context ctx; failure_kind fk; uw_periodic *ps; loggers *ls = malloc(sizeof(loggers)); int id; + char *stackSize_s; + + if ((stackSize_s = getenv("URWEB_STACK_SIZE")) != NULL && stackSize_s[0] != 0) { + stackSize = atoll(stackSize_s); + + if (stackSize <= 0) { + fprintf(stderr, "Invalid stack size \"%s\"\n", stackSize_s); + exit(1); + } + } ls->app = app; ls->logger_data = logger_data; @@ -141,7 +169,7 @@ { pthread_t thread; - if (uw_time_max && pthread_create(&thread, NULL, ticker, NULL)) { + if (uw_time_max && pthread_create_big(&thread, NULL, ticker, NULL)) { fprintf(stderr, "Error creating ticker thread\n"); exit(1); } @@ -174,7 +202,7 @@ arg->ls = ls; arg->pdic = *ps; - if (pthread_create(&thread, NULL, periodic_loop, arg)) { + if (pthread_create_big(&thread, NULL, periodic_loop, arg)) { fprintf(stderr, "Error creating periodic thread\n"); exit(1); } diff -r 001638622c4f -r 4d0b80dd4c37 tests/overflow.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/overflow.ur Tue Aug 02 14:31:37 2011 -0400 @@ -0,0 +1,8 @@ +fun makeList n = if n = 0 then [] else 1 :: makeList (n - 1) + +fun doit {N = n} = return {[List.length (makeList (readError n))]} + +fun main () = + return +
+
diff -r 001638622c4f -r 4d0b80dd4c37 tests/overflow.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/overflow.urp Tue Aug 02 14:31:37 2011 -0400 @@ -0,0 +1,4 @@ +rewrite all Overflow/* + +$/list +overflow diff -r 001638622c4f -r 4d0b80dd4c37 tests/overflow.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/overflow.urs Tue Aug 02 14:31:37 2011 -0400 @@ -0,0 +1,1 @@ +val main : unit -> transaction page