Re: [patch] perchild.c (Re: setjmp/longjmp vs try/throw/catch)
On Wed, 21 Jul 2004 05:33:18 +0900 (JST), Tsuyoshi SASAMOTO <[EMAIL PROTECTED]> wrote: > And... in perchild.c, I found setjmp/longjmp is used unsafely > (one jmpbuffer is shared by all threads). (a) based on ancient experience, I'm surprised it doesn't use SIGsetjmp()/SIGlongjmp(); event Apache 1.3 was smart enough to do that (just not smart enough not to use longjmp in the first place ;) ) (b) I omitted the unrelated fix which was part of your patch; care to provide an explanation? Thanks, Jeff
Re: [patch] perchild.c (Re: setjmp/longjmp vs try/throw/catch)
On Wed, 21 Jul 2004 05:33:18 +0900 (JST), Tsuyoshi SASAMOTO <[EMAIL PROTECTED]> wrote: > And... in perchild.c, I found setjmp/longjmp is used unsafely > (one jmpbuffer is shared by all threads). patch looks reasonable on first glance; I'll look further with the intention of committing soon-ish; bother me privately in a few days if I forget ;) (thanks!)
Re: [patch] perchild.c (Re: setjmp/longjmp vs try/throw/catch)
On 20-Jul-04, at 3:33 PM, Tsuyoshi SASAMOTO wrote: Please refer to this discussion about thread safety of setjmp/longjmp: http://groups.google.com/groups? [EMAIL PROTECTED] The signal-to-noise ratio in that thread is very low :) It is clear that setjmp/longjmp are *not* signal-safe; furthermore, signals interact badly with threads. It is certainly not ok to use longjmp in a signal handler, since there is no way of knowing which thread a signal handler might be running in. This does not make setjmp/longjmp thread unsafe (IMHO). As Posix memorably states, using longjmp with a jump buffer from a different thread context is a "questionable practice ... not worthy of standardization". R.
[patch] perchild.c (Re: setjmp/longjmp vs try/throw/catch)
>Switching to setjmp/longjmp does appear to work well with apache and gcc. >But that leaves me wondering if I need to worry about thread-safety. >Is using setjmp/longjmp with Worker or Windoze MPM asking for trouble? >And if so, is there an alternative approach I could try? Please refer to this discussion about thread safety of setjmp/longjmp: http://groups.google.com/[EMAIL PROTECTED] And... in perchild.c, I found setjmp/longjmp is used unsafely (one jmpbuffer is shared by all threads). Tsuyoshi SASAMOTO [EMAIL PROTECTED] --- httpd-2.0/server/mpm/experimental/perchild/perchild.c Tue Mar 16 08:08:41 2004 +++ httpd-2.0/server/mpm/experimental/perchild/perchild.c Wed Jul 21 04:26:15 2004 @@ -137,7 +137,7 @@ static int requests_this_child; static int num_listensocks = 0; static ap_pod_t *pod; -static jmp_buf jmpbuffer; +static jmp_buf *jmpbuffers; struct child_info_t { uid_t uid; @@ -617,7 +617,7 @@ bodylen = strlen(body); headers = iov.iov_base; -headerslen = body - headers; +headerslen = body - 1 - headers; bucket = apr_bucket_heap_create(body, bodylen, NULL, alloc); APR_BRIGADE_INSERT_HEAD(bb, bucket); @@ -758,7 +758,7 @@ } } apr_thread_mutex_unlock(idle_thread_count_mutex); -if (setjmp(jmpbuffer) != 1) { +if (setjmp(jmpbuffers[thread_num]) != 1) { process_socket(ptrans, csd, conn_id, bucket_alloc); } else { @@ -1668,6 +1668,8 @@ } ap_child_table = (ap_ctable *)apr_pcalloc(p, server_limit * sizeof(ap_ctable)); +jmpbuffers = (jmp_buf *)apr_palloc(p, thread_limit * sizeof(jmp_buf)); + return OK; } @@ -1704,7 +1706,7 @@ ap_server_conf, "Could not pass request to proper " "child, request will not be honored."); } -longjmp(jmpbuffer, 1); +longjmp(jmpbuffers[thread_num], 1); } return OK; }