On Fri, Nov 11, 2016 at 8:03 AM, Vitaliy Bondarchuk <
[email protected]> wrote:

> Honestly i think that even if there is a case when you have to use a
> reader from multiple threads I don't clearly understand why you use locks
> (by the way - exclusive lock here) in the ReaderArena::tryGetSegment
> method.
> imho, may be if it possible it's better to initialize reader in his
> constructor and then keep it immutable.
> Or. May be it will be nice if even on Vista and later I can create
> single-thread reader (may by by optional parameter in constructor). So the
> reader will not spend time for unnecessary lock functions
>

The issue here is lazy loading. MessageReader can lazily load segments, so
that you can start processing the data in the first segment before the
other segments have been received. It's important for lazily-initialized
data structures to be thread-safe since programmers would reasonably expect
that the structure is immutable and therefore would expect it to be safe to
use in multiple threads concurrently.

That said, this lazy-loading feature of MessageReader is probably a
misfeature and we should probably get rid of it. When reading from disk,
it's much cleaner to use mmap() to get the same effect. When reading from a
network, lazy loading is a bad idea because as soon as you try to follow a
pointer to a later segment it will block waiting for the segment to arrive,
which could be never. As a result we never actually use lazy loading for
network messages in practice.

So, I think we'll remove this feature at some point.

-Kenton

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to