At 07:54 +0100 98/06/17, Simon L Peyton Jones wrote:
>> Ideally, I would like to write cgifunctions of type:
>>
>> myCGIFunction:: [HTTPRequest]->[DatabaseVersion]->
>>                      ([HTTPResponse],[DatabaseChanges])
>>
>> HTTPRequests come from _middleware_ that recieves http requests from the
>> httpd and append them to a list. Attempts to get the next item in the
>> HTTPRequest list block until requests come in to fill the list.
...
>I gather that HTTPRequests and DataBaseVersions arrive
>asynchronously and unpredictably.  So how does myCGIFunction know
>which list to probe first?  Whichever it chooses it may block on
>one while there is data on the other. Unless I'm misunderstanding.
>
>You need to be able to say "wait until there's input available
>on one of these two ports, and tell me which".  Something like
>the Unix select call.  GHC's Posix library has such a thing,
>but you can't use it in the way you describe because myCGIFunction
>is a pure function on lists.

  I think one can use different techniques when doing concurrent
programming: One is to set forth different processes, and rather imperative
waiting for them in a loop to finish, which is my guess is what SLPJ thinks
of here.

  But one can do something more functional: In this model, the arguments
are references which handshake with the function. The function sets off
threads for HTTPRequests and DataBaseVersions, and go idle; these threads
report back when they have something to report, and the stuff is processed
then.

  But I found it rather difficult to implement this style with POSIX (Java)
threads: It is hard to guarantee that the computations does not hang. What
I needed was to be able to guarantee that certain sequences in the
implementation cannot the halted in the middle, but that is not possible
with pre-emotive threads I think.

  Hans Aberg
                  * Email: Hans Aberg <mailto:[EMAIL PROTECTED]>
                  * Home Page: <http://www.matematik.su.se/~haberg/>
                  * AMS member listing: <http://www.ams.org/cml/>



Reply via email to