Re: Stdio.Buffer.set_buffer_mode revisited

"Stephen R. van den Berg" <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <[email protected]>
Per Hedbor () @ Pike (-) importm?te f?r mailinglistan wrote:
>A class like this might be useful to have somewhere, incidentally:

>| protected Thread.Thread backend_thread;
>| /* initialized in various ways in our code. */
>|
>| class Blocking( function(function(mixed:void),mixed...:void) async_func )

>The main advantage of this is that there is no longer any need for a
>single thread in the low-level code, and in fact, it works even if the
>client code does not use threads either. Everything is non-blocking,
>the blocking API either waits for the result or runs the backend, as
>needed.

I'll try and wrap my head around this and see if it helps me reduce/eliminate
the threads in the pgsql driver.

>Personally I tend to see use of threads as a failure. :)

Well, usually I'd agree, however, if you want to process incoming network
data in a streaming fashion, then using callbacks usually means that at
some point you *are* copying data.  For small amounts that won't be a problem,
but in case of the database, we sometimes can handle queries that return
several megabytes worth of data, so I want to avoid all unnecessary copies.
Using threading allows me to keep state information in the thread without
needing to copy things around to (re)package it for the callback.
-- 
Stephen.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.