[Lldb-commits] [PATCH] D25783: [Host] handle short reads and writes

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 19 13:25:00 PDT 2016


zturner added a comment.

In https://reviews.llvm.org/D25783#574679, @labath wrote:

> I am not sure the "append" thing is actually a "fix". I consider it more like a feature of the append mode. It's also nice that it guarantees atomicity of writes even if two processes are writing to the same file (very useful for logging, although I'm not sure if that goes through these functions). I think we should keep the original behavior of append mode, as that is the behavior anyone familiar with standard file APIs will expect.


There are many other problems with this code if we want to deal with atomicity.  For example, the whole point of this patch was to handle short reads and writes.  Well, if you have a short read or a write, then reading and writing a subsequent chunk is not atomic.

That being said, I don't think it's hugely important here.  The worst that will happen is two log messages will be printed out of order.  I don't think anything will be corrupt or interwoven.  For example, if two threads come in at the same time and both compute the same file size, they will both attempt to write at the same offset.  One will win, the other will insert right before the message.  So it's possible the two could wind up reversed, but that's about it.

Only way to deal with multi-threading correctly is to put all this in a mutex.


https://reviews.llvm.org/D25783





More information about the lldb-commits mailing list