[plt-scheme] spawning threads in web server

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Mar 1 15:34:45 EST 2004

I don't understand why you need threads here. How about

(let ([do-now #t])
  (send/suspend (lambda (url)
   (if (begin (send-email url) (begin0 do-now (set! do-now #f)))
       (do-after-return-user-clicks-on-url)
       (do-things-now))))

In general I agree that continuations should be liberated from threads. 
Matthew may think so, too, now.

-- Matthias


On Mar 1, 2004, at 3:05 PM, David Van Horn wrote:

>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> It's easy enough to have a servlet that pauses computation, sends a 
> URL to an email address and then resumes once the URL is visited.  I 
> have a slightly different situation.  I'd like to have the computation 
> continue for the user, but email a URL that will continue down another 
> path of computation when visited.
>
> I use this to notify the administrator about certain user actions that 
> require attention.  The administrator is sent a URL that when visited 
> will have forms tailored for the specific user and required action.
>
> I had thought something like this would work:
>
>   (send/suspend/dispatch
>    `(html
>      (form ((action
>              ,(lambda (request)
>                 ...
>                 (thread
>                  (lambda ()
>                    ((lambda (request) ...)
>                     (send/suspend
>                      (lambda (k-url)
>                        (send-email admin k-url)
>                        `(html
>                          (form ;; for admin use.
>                           ...)))))))
>                 (send/finish
>                  '(html (p "thanks for notifying the admins."))))))
>
>            ... ;; for user use.
>            )))
>
> But this gives the following error:
>
> Servlet exception: "continuation application: attempted to apply 
> foreign continuation (created in another thread)"
>
> I don't see how to do this without spawning a new thread; perhaps I'm 
> overlooking something obvious.  Any help would be appreciated.
>
> Thanks,
> David



Posted on the users mailing list.