zboxfs / zbox

Zero-details, privacy-focused in-app file system.
https://zbox.io/fs/
Apache License 2.0
1.53k stars 74 forks source link

Document File thread safety #55

Closed theduke closed 4 years ago

theduke commented 4 years ago

It seems like writing to a file repeatedly from multiple threads is not possible and is terminated with a NotInTrans error.

I stumbled over this while trying to do so from a async fn.

burmecia commented 4 years ago

Can you post your full source code? Without details, it's hard to see what's the actual problem is.

theduke commented 4 years ago

Well just looking it at the code makes it obvious: a File can't receive consecutive writes from different threads, since begin_write() initializes a thread local TXID, which will not be set on a second write from a different thread.

So with the current design, File should really be !Send.

burmecia commented 4 years ago

Your looking is right. When shared with multiple threads, File works like a reader-writer lock, that is, you can only have one thread to modify it, but you can have multiple threads to read. So I think !Send is still valid.