[Haskell-cafe] Re: Stream processors

Peter Simons simons at cryp.to
Thu Oct 21 17:19:32 EDT 2004


Ben Rudiak-Gould writes:

 >   bar :: StreamProc ctx a -> IO (a,a)
 >   bar sp = do
 >     ctx <- start sp
 >     (ptr1,n1) <- ...
 >     (ptr2,n2) <- ...
 >     ctx1 <- feed sp ctx (ptr1,n1)
 >     ctx2 <- feed sp ctx (ptr2,n2)
 >     val1 <- commit sp ctx1
 >     val2 <- commit sp ctx2
 >     return (val1,val2)

Ah! Now I understand what you meant with single-threaded
versus multi-threaded use of the stream processor.

Well, in the general case the result would be undefined,
because not every stream processor allows a context to be
re-used. The SHA1 implementation I use, for example, has a
context of

  Ptr Sha1Context

..., so both val1 and val2 would be the hash of the
concatenation of both buffers. Which is not what you'd
expect. A different implementation, on the other hand, might
give you the hash of the first and second block
respectively.

Hmmm. So I have those options:

 (1) If you want to use _any_ stream processor, you must use
     it single-threadedly. If you use it multi-threadedly,
     you have to know what you're doing.

 (2) Have distinct types (or classes) for stream processors
     that allow the context to be re-used and for those
     which do not.

So far, I've implicitly used (1).

Peter



More information about the Haskell-Cafe mailing list